This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.0.
Semaphores - kombu.asynchronous.semaphore
¶
Semaphores and concurrency primitives.
- class kombu.asynchronous.semaphore.LaxBoundedSemaphore(value)[source]¶
Asynchronous Bounded Semaphore.
Lax means that the value will stay within the specified range even if released more times than it was acquired.
Example
>>> x = LaxBoundedSemaphore(2)
>>> x.acquire(print, 'HELLO 1') HELLO 1
>>> x.acquire(print, 'HELLO 2') HELLO 2
>>> x.acquire(print, 'HELLO 3') >>> x._waiters # private, do not access directly [print, ('HELLO 3',)]
>>> x.release() HELLO 3
- acquire(callback, *partial_args, **partial_kwargs)[source]¶
Acquire semaphore.
This will immediately apply
callback
if the resource is available, otherwise the callback is suspended until the semaphore is released.- Parameters
callback (Callable) – The callback to apply.
*partial_args (Any) – partial arguments to callback.