# ``twisted`.`internet`.`defer`.`DeferredLock``

class documentation

`class DeferredLock(_ConcurrencyPrimitive): (source)`

View In Hierarchy

A lock for event driven systems.

Method | `acquire` | Attempt to acquire the lock. Returns a `Deferred` that fires on lock acquisition with the `DeferredLock` as the value. If the lock is locked, then the Deferred is placed at the end of a waiting list.
Method | `release` | Release the lock. If there is a waiting list, then the first `Deferred` in that waiting list will be called back.
Instance Variable | `locked` | `True` when this Lock has been acquired, false at all other times. Do not change this value, but it is useful to examine for the equivalent of a "non-blocking" acquisition.
Method | `_cancelAcquire` | Remove a deferred d from our waiting list, as the deferred has been canceled.

Inherited from `_ConcurrencyPrimitive`:

Method | `__aenter__` | We can be used as an asynchronous context manager.
Method | `__aexit__` | Undocumented
Method | `__init__` | Undocumented
Method | `run` | Acquire, run, release.
Instance Variable | `waiting` | Undocumented
Method | `_releaseAndReturn` | Undocumented

def acquire(self): (source)
overrides `twisted.internet.defer._ConcurrencyPrimitive.acquire`
Attempt to acquire the lock. Returns a `Deferred` that fires on lock acquisition with the `DeferredLock` as the value. If the lock is locked, then the Deferred is placed at the end of a waiting list.

Returns
a `Deferred` | a `Deferred` which fires on lock acquisition.

def release(self): (source)
overrides `twisted.internet.defer._ConcurrencyPrimitive.release`

Release the lock. If there is a waiting list, then the first `Deferred` in that waiting list will be called back.

Should be called by whomever did the `acquire`() when the shared resource is free.

locked: `bool` = (source)
`True` when this Lock has been acquired, false at all other times. Do not change this value, but it is useful to examine for the equivalent of a "non-blocking" acquisition.
def _cancelAcquire(self, d): (source)

Remove a deferred d from our waiting list, as the deferred has been canceled.

Note: We do not need to wrap this in a try/except to catch d not being in self.waiting because this canceller will not be called if d has fired. release() pops a deferred out of self.waiting and calls it, so the canceller will no longer be called.

Parameters
d:`Deferred[_DeferredLockT]` | The deferred that has been canceled.