@@ -847,11 +847,6 @@ are suitable for use in loops. The separate *filling* and *draining* phases
847847assure that all threads get released (drained) before any one of them can loop
848848back and re-enter the barrier. The barrier fully resets after each cycle.
849849
850- If any of the predecessor tasks can hang or be delayed, a barrier can be created
851- with an optional *timeout * parameter. Then if the timeout period elapses before
852- all the predecessor tasks reach the barrier point, all waiting threads are
853- released and a :exc: `~threading.BrokenBarrierError ` exception is raised.
854-
855850Example of using barriers::
856851
857852 def get_votes(site):
@@ -870,6 +865,26 @@ is similar to one with :meth:`threading.Thread.join`, but the threads stay alive
870865and continue to do work (summarizing ballots) after the barrier point is
871866crossed.
872867
868+ If any of the predecessor tasks can hang or be delayed, a barrier can be created
869+ with an optional *timeout * parameter. Then if the timeout period elapses before
870+ all the predecessor tasks reach the barrier point, all waiting threads are
871+ released and a :exc: `~threading.BrokenBarrierError ` exception is raised::
872+
873+ def get_votes(site):
874+ ballots = conduct_election(site)
875+ try:
876+ all_polls_closed.wait(timeout = midnight - time.now())
877+ except BrokenBarrerError:
878+ lockbox = seal_ballots(ballots)
879+ queue.put(lockbox)
880+ else:
881+ totals = summarize(ballots)
882+ publish(site, totals)
883+
884+ In this example, the barrier enforces a more robust rule. If some election
885+ sites do not finish before midnight, the barrier times-out and the ballots are
886+ sealed and deposited in a queue for later handling.
887+
873888See `Barrier Synchronization Patterns
874889<http://parlab.eecs.berkeley.edu/wiki/_media/patterns/paraplop_g1_3.pdf> `_ for
875890more examples of how barriers can be used in parallel computing. Also, there is
0 commit comments