This document describes the current stable version of Kombu (5.3). For development docs, go here.

Semaphores - kombu.asynchronous.semaphore

Semaphores and concurrency primitives.

class kombu.asynchronous.semaphore.DummyLock[source]

Pretending to be a lock.

class kombu.asynchronous.semaphore.LaxBoundedSemaphore(value: int)[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: Callable[P, None], *partial_args: P.args, **partial_kwargs: P.kwargs) bool[source]

Acquire semaphore.

This will immediately apply callback if the resource is available, otherwise the callback is suspended until the semaphore is released.

Arguments:

callback (Callable): The callback to apply. *partial_args (Any): partial arguments to callback.

clear() None[source]

Reset the semaphore, which also wipes out any waiting callbacks.

grow(n: int = 1) None[source]

Change the size of the semaphore to accept more users.

release() None[source]

Release semaphore.

Note:

If there are any waiters this will apply the first waiter that is waiting for the resource (FIFO order).

shrink(n: int = 1) None[source]

Change the size of the semaphore to accept less users.