dragon.native.semaphore
The Dragon native implementation of the classical semaphore synchronization object.
The API follows the Python Multiprocessing API of Semaphore and extends it with
a get_value()
method.
Classes
This class implements Semaphore objects on top of Dragon channels. |
- class Semaphore
Bases:
object
This class implements Semaphore objects on top of Dragon channels. We use a Dragon native Lock to protect a channel with a single entry that is used to count the number of acquire and release calls. We extend the standard API with a get_value method to ask the Semaphore for the current value.
- __init__(value: int = 1, *, m_uid: int = 4611686018427387904, bounded=False)
Create a Semaphore object that can be shared across Dragon processes.
- acquire(blocking: bool = True, timeout: float = None) bool
Acquire the Semaphore, decrementing the counter, blocking other processes when the counter is decremented to 0.
- release(n: int = 1) None
Release the Semaphore, incrementing the internal value by n, thus unblocking up to n processes.
- Parameters:
n (int , optional) – how much to increment the internal value by, defaults to 1
- serialize()
Return a serialized, base64 encoded, string that may be used by C++ code to attach to this semaphore. Any process attaching to this semaphore does not participate in the ref counting of the semaphore. In other words, the lifetime of the semaphore is managed by the Python process that creates it or other Python processes that have handles to it. C++ code that wishes to use it can, but the Python process must live/ wait to exit until the C++ code is done with it.
- Returns:
A serialized, base64 encoded string that can be used
to attach to the semaphore by the C++ Semaphore implementation. :rtype: str