New GitHub issue #93213 from hauntsaninja:<br>
<hr>
<pre>
**Feature or enhancement**
It would be useful to be able to access the value of `threading.Semaphore._value` as part of the public API of `Semaphore`, say via a `get_value` method.
**Pitch**
The value is useful for debugging and testing. It also has educational value by allowing users to see the internal state of a Semaphore.
https://cs.github.com/?scopeName=All+repos&scope=&q=semaphore._value+language%3Apython# finds 68 uses of the exact phrase "semaphore._value" on Github, so I'm not alone in wanting access to this.
**Previous discussion**
`asyncio.locks.Semaphore` has a `locked` method that exposes whether the value of the Semaphore is zero. It does appear that many of the uses are comparing the value to zero, so adding a `locked` method to `threading.Semaphore` would be sufficient for a lot of usage.
While writing this issue, I noticed that in 3.11, `threading.Semaphore` has its value printed in `__repr__` (changed in #20534, the bpo mentions "expose their public states" as the rationale)
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/93213">View on GitHub</a>
<p>Labels: type-feature</p>
<p>Assignee: </p>