You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect exception message in Barrier.__init__ #129403
# Add a code block here, if required>>>importthreading>>>x=threading.Barrier(parties=0.5)
Traceback (mostrecentcalllast):
File"<pyshell#0>", line1, in<module>x=Barrier(parties=0.5)
ValueError: partiesmustbe>0
Yes. As you see 0.5 is below 0.
To solve this problem, adding this sentence is viable.
classBarrier:
"""Implements a Barrier. Useful for synchronizing a fixed number of threads at known synchronization points. Threads block on 'wait()' and are simultaneously awoken once they have all made that call. """def__init__(self, parties, action=None, timeout=None):
"""Create a barrier, initialised to 'parties' threads. 'action' is a callable which, when supplied, will be called by one of the threads after they have all entered the barrier and just prior to releasing them all. If a 'timeout' is provided, it is used as the default for all subsequent 'wait()' calls. #if not isinstance(parties, int): # raise TypeError("parties must be an integer") if parties < 1: raise ValueError("parties must be > 0") """self._cond=Condition(Lock())
self._action=actionself._timeout=timeoutself._parties=partiesself._state=0# 0 filling, 1 draining, -1 resetting, -2 brokenself._count=0
Activity
Locked-chess-official commentedon Jan 28, 2025
I think that it maybe a wrong tips bug. The judgement statement is "if parties <1'", but the exception's tips is "parties must be > 0".
sobolevn commentedon Jan 28, 2025
The same happens here:
cpython/Lib/asyncio/locks.py
Lines 487 to 488 in 180ee43
cpython/Lib/threading.py
Lines 696 to 697 in 180ee43
PR with the exc message change from
> 0to>= 1is welcome! 👍[-]0.5<0[/-][+]Incorrect exception message in `Barrier.__init__`[/+]gh-129403: Fix `ValueError` messages in `asyncio.Barrier` and `thread…
pythongh-129403: Fix `ValueError` messages in `asyncio.Barrier` and `…
pythongh-129403: Fix `ValueError` messages in `asyncio.Barrier` and `…
[3.12] gh-129403: Fix `ValueError` messages in `asyncio.Barrier` and …
[3.13] gh-129403: Fix `ValueError` messages in `asyncio.Barrier` and …
pythongh-129403: Fix `ValueError` messages in `asyncio.Barrier` and `…