class twisted.internet.defer.DeferredSemaphore(_ConcurrencyPrimitive): (source)
A semaphore for event driven systems.
If you are looking into this as a means of limiting parallelism, you might find twisted.internet.task.Cooperator
more useful.
Instance Variable | limit | At most this many users may acquire this semaphore at once. |
Instance Variable | tokens | The difference between limit and the number of users which have currently acquired this semaphore. |
Method | __init__ | |
Method | acquire | Attempt to acquire the token. |
Method | release | Release the token. |
Method | _cancelAcquire | Remove a deferred d from our waiting list, as the deferred has been canceled. |
Inherited from _ConcurrencyPrimitive:
Instance Variable | waiting | Undocumented |
Method | run | Acquire, run, release. |
Method | __aenter__ | We can be used as an asynchronous context manager. |
Method | __aexit__ | Undocumented |
Method | _releaseAndReturn | Undocumented |
limit
and the number of users which have currently acquired this semaphore.int
)
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 | The deferred that has been canceled. |