equal
deleted
inserted
replaced
231 |
231 |
232 def __enter__(self): |
232 def __enter__(self): |
233 return self |
233 return self |
234 |
234 |
235 def __exit__(self, exc_type, exc_value, exc_tb): |
235 def __exit__(self, exc_type, exc_value, exc_tb): |
236 self.release() |
236 success = all(a is None for a in (exc_type, exc_value, exc_tb)) |
|
237 self.release(success=success) |
237 |
238 |
238 def __del__(self): |
239 def __del__(self): |
239 if self.held: |
240 if self.held: |
240 warnings.warn( |
241 warnings.warn( |
241 "use lock.release instead of del lock", |
242 "use lock.release instead of del lock", |
406 finally: |
407 finally: |
407 if self.acquirefn: |
408 if self.acquirefn: |
408 self.acquirefn() |
409 self.acquirefn() |
409 self._inherited = False |
410 self._inherited = False |
410 |
411 |
411 def release(self): |
412 def release(self, success=True): |
412 """release the lock and execute callback function if any |
413 """release the lock and execute callback function if any |
413 |
414 |
414 If the lock has been acquired multiple times, the actual release is |
415 If the lock has been acquired multiple times, the actual release is |
415 delayed to the last release call.""" |
416 delayed to the last release call.""" |
416 if self.held > 1: |
417 if self.held > 1: |
431 pass |
432 pass |
432 # The postrelease functions typically assume the lock is not held |
433 # The postrelease functions typically assume the lock is not held |
433 # at all. |
434 # at all. |
434 if not self._parentheld: |
435 if not self._parentheld: |
435 for callback in self.postrelease: |
436 for callback in self.postrelease: |
436 callback() |
437 callback(success) |
437 # Prevent double usage and help clear cycles. |
438 # Prevent double usage and help clear cycles. |
438 self.postrelease = None |
439 self.postrelease = None |
439 |
440 |
440 |
441 |
441 def release(*locks): |
442 def release(*locks): |