dragon.mpbridge.synchronize.DragonBoundedSemaphore

class DragonBoundedSemaphore

Bases: Semaphore

A bounded sempahore co-located on the same node by default as the creating process

__init__(*args, ctx, **kwargs)

Create a Semaphore object that can be shared across Dragon processes.

Parameters:
  • value (int , optional) – initial value for the counter, defaults to 1

  • m_uid (int , optional) – dragon managed memory pool id to use, defaults to the standard pool.

  • bounded (bool , optional) – set if the value of the Semaphore cannot exceed its initial value, defaults to False

Methods

__init__(*args, ctx, **kwargs)

Create a Semaphore object that can be shared across Dragon processes.

acquire([blocking, timeout])

Acquire the Semaphore, decrementing the counter, blocking other processes when the counter is decremented to 0.

get_value()

Get the value of the internal counter without acquiring the Semaphore.

release([n])

Release the Semaphore, incrementing the internal value by n, thus unblocking up to n processes.

serialize()

Return a serialized, base64 encoded, string that may be used by C++ code to attach to this semaphore.

__init__(*args, ctx, **kwargs)

Create a Semaphore object that can be shared across Dragon processes.

Parameters:
  • value (int , optional) – initial value for the counter, defaults to 1

  • m_uid (int , optional) – dragon managed memory pool id to use, defaults to the standard pool.

  • bounded (bool , optional) – set if the value of the Semaphore cannot exceed its initial value, defaults to False

acquire(blocking: bool = True, timeout: float = None) bool

Acquire the Semaphore, decrementing the counter, blocking other processes when the counter is decremented to 0.

Parameters:
  • blocking (bool , optional) – block the process if the Semaphore cannot be acquired immediately, defaults to True

  • timeout (float , optional) – timeout for a block in seconds, defaults to None (i.e. no timeout)

get_value() int

Get the value of the internal counter without acquiring the Semaphore.

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