# Request for review: threading.Barrier hangs indefinitely when arg parties \< 0 or invalid type

**URL:** <https://discuss.python.org/t/request-for-review-threading-barrier-hangs-indefinitely-when-arg-parties-0-or-invalid-type/59498>\
**Category:** Core Development\
**Tags:** review-request\
**Created:** [July 30, 2024, 3:54am UTC](https://discuss.python.org/t/request-for-review-threading-barrier-hangs-indefinitely-when-arg-parties-0-or-invalid-type/59498 "2024-07-30T03:54:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pygeek](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pygeek/32/20423_2.png) [@pygeek](https://discuss.python.org/u/pygeek)\
**Post date:** [July 30, 2024, 3:54am UTC](https://discuss.python.org/t/request-for-review-threading-barrier-hangs-indefinitely-when-arg-parties-0-or-invalid-type/59498/1 "2024-07-30T03:54:55Z")

</div>

`threading.Barrier` at no point checks for valid `parties`. `parties`, of a negative value, or invalid type hang indefinitely on `.wait()`. This behavior is inconsistent from the behavior of any other `threading` primitives, which either conduct sanity checks on args during initialization, or fail at some point in their execution. It should also be noted that the current behavior is inconsistent with `asyncio.Barrier`.

Steps to reproduce:

```python
from threading import Barrier
# negative
barrier = Barrier(-1) # <threading.Barrier at 0x10aa789b0: waiters=0/-1>
barrier.wait()

# invalid type string
barrier = Barrier("test") # <threading.Barrier at 0x10ae64980: waiters=0/test>
barrier.wait()

# invalid type float
barrier = Barrier(0.5) # <threading.Barrier at 0x10aa7a570: waiters=0/0.5>
barrier.wait()

# invalid type object
barrier = Barrier(object()) # <threading.Barrier at 0x10ae4f500: waiters=0/<object object at 0x10a878730>>
barrier.wait()

```

> <https://github.com/python/cpython/issues/121474>
>
> \# Bug report
> 
> \### Bug description:
> 
> \`threading.Barrier\` at no point checks f…or valid \`parties\`. \`parties\`, of a negative value, or invalid type hang indefinitely on \`.wait()\`. This behavior is inconsistent from the behavior of any other \`threading\` primitives, which either conduct sanity checks on args during initialization, or fail at some point in their execution.
> 
> Steps to reproduce:
> 
> \`\`\`python
> from threading import Barrier
> \# negative
> barrier = Barrier(-1) # \<threading.Barrier at 0x10aa789b0: waiters=0/-1\>
> barrier.wait()
> 
> \# invalid type string
> barrier = Barrier("test") # \<threading.Barrier at 0x10ae64980: waiters=0/test\>
> barrier.wait()
> 
> \# invalid type float
> barrier = Barrier(0.5) # \<threading.Barrier at 0x10aa7a570: waiters=0/0.5\>
> barrier.wait()
> 
> \# invalid type object
> barrier = Barrier(object()) # \<threading.Barrier at 0x10ae4f500: waiters=0/\<object object at 0x10a878730\>\>
> barrier.wait()
> \`\`\`
> 
> 
> \### CPython versions tested on:
> 
> CPython main branch
> 
> \### Operating systems tested on:
> 
> macOS
> 
> 
> \### Linked PRs
> \* gh-121480

> <https://github.com/python/cpython/pull/121480>
>
> \* Issue: gh-121474
