ID EN
Threading

Barrier

Python 3.11

Create a barrier object for parties number of threads. An action, when provided, is a callable to be called by one of the threads when they are released. timeout is the default timeout value if none is specified for the wait() method.

Syntax

PYTHON
class threading.Barrier(parties, action=None, timeout=None)

Examples

Example 1
PYTHON
i = barrier.wait()
if i == 0:
     Only one thread needs to print this
    print("passed the barrier")

See Also

wait() BrokenBarrierError BrokenBarrierError wait() BrokenBarrierError