dragon.native.barrier

The Dragon native barrier is an object for parties number of threads. The class can be initialized with a number of threads, an action, and timeout. The functions are wait, reset, and abort.

Classes

Barrier

This class implements Barrier objects with a Dragon channel.

Exceptions

BrokenBarrierError

exception BrokenBarrierError

Bases: ChannelBarrierBroken

class Barrier

Bases: object

This class implements Barrier objects with a Dragon channel. The Barrier handles parties of threads that are 2 and more, number of waiting threads, and whether or not the barrier is broken.

__init__(parties: int = 2, action: callable = None, timeout: float = None, m_uid: int = 4611686018427387904)

Initialize a barrier object :param parties: number of parties for the barrier to act upon :type parties: int, optional, > 1 :param action: class that the barrier calls upon :type callable: optional :param timeout: timeout for barrier :type timeout: float, optional :param m_uid: memory pool to create the channel in, defaults to _DEF_MUID :type m_uid: int, optional

wait(timeout: float = None) int

When all the processes party to the barrier have called wait, they are all released simultaneously. The timeout for wait takes precedence over constructor. :param timeout: timeout for barrier :type timeout: float, optional :rtype: None

reset() None

Barrier is set to empty state. Any waiters receive BrokenBarrierError. :rtype: None

abort() None

The barrier is broken. Any waiters that are in wait state will receive BrokenBarrierError. :rtype: None

destroy() None

Destroys the underlying Dragon resources so the space can be re-used.

Destroys underlying Dragon resource. Only do this when you know all references to the object have been deleted.

Returns:

None

Return type:

NoneType

property parties
property n_waiting
property broken
serialize()

Return a serialized, base64 encoded, string that may be used by C++ code to attach to this barrier. Any process attaching to this barrier does not participate in the ref counting of the barrier. In other words, the lifetime of the barrier 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 barrier by the C++ Barrier implementation. :rtype: str