a = threading. Barrier(float('nan')) #the number changed to be NaN due to the system or the attackers'attackion.
It won’t be failed because the condition to failed is ‘parties<1’, but ‘NaN<1’ is False. In “asyncio.Barrier”, it is the same result.
In some other functions or methods in other modules that need a positive number, it will raise an Exception:
time.sleep(float('nan')) #failed
multiprocessing.Pipe()[0].poll(float('nan')) #failed
multiprocessing.Process().join(float('nan')) #failed
and so on.
NaN is not a reasonable value to use.
You must call Barrier with a int number of processes to wait for, as is documented. See threading — Thread-based parallelism — Python 3.13.2 documentation
1 Like
Yes, that’s True. But that’s not mandatory. In other functions or methods or classes, it leads to an Exception, but in here all are normal so that the Barrier will wait for NaN threads. I mean that it maybe useful to raise an Exception for these unreasonable values.
You want a change to Barrier() to raise an exception if it is called with a value that cannot be coerced to an int?
I think that sometimes it is needed. Waiting for a number of threads that cannot be reached is harmful for the system, especially the obvious.
I changed the title to state what you are asking for.
I hope that was alright.