Wait for the barrier. When the specified number of threads have started waiting, they are all simultaneously awoken. If an 'action' was provided for the barrier, one of the threads will have executed that callback prior to returning. Returns an individual index numbe
(self, timeout=None)
| 710 | f" waiters={self.n_waiting}/{self.parties}>") |
| 711 | |
| 712 | def wait(self, timeout=None): |
| 713 | """Wait for the barrier. |
| 714 | |
| 715 | When the specified number of threads have started waiting, they are all |
| 716 | simultaneously awoken. If an 'action' was provided for the barrier, one |
| 717 | of the threads will have executed that callback prior to returning. |
| 718 | Returns an individual index number from 0 to 'parties-1'. |
| 719 | |
| 720 | """ |
| 721 | if timeout is None: |
| 722 | timeout = self._timeout |
| 723 | with self._cond: |
| 724 | self._enter() # Block while the barrier drains. |
| 725 | index = self._count |
| 726 | self._count += 1 |
| 727 | try: |
| 728 | if index + 1 == self._parties: |
| 729 | # We release the barrier |
| 730 | self._release() |
| 731 | else: |
| 732 | # We wait until someone releases us |
| 733 | self._wait(timeout) |
| 734 | return index |
| 735 | finally: |
| 736 | self._count -= 1 |
| 737 | # Wake up any threads waiting for barrier to drain. |
| 738 | self._exit() |
| 739 | |
| 740 | # Block until the barrier is ready for us, or raise an exception |
| 741 | # if it is broken. |