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
multiprocessing.Semaphore has undocumented get_value() method #84974
I concur with @gst . Was this never intended to be officially supported or was it just implemented only for certain systems (and thus not yet documented)?
It appears to not function on macOS (not implemented) but does work on Linux (x86/Python3.8 and ARM64/Python3.6).
Thanks, makes sense to add tests before promoting it officially.
Regarding cross-platform support, is there a reason that the method can't just apply for OSes which support the necessary underlying C functions? For example (and understandably) different start methods are supported with a comment in the documentation: "Available on POSIX platforms which support passing file descriptors over Unix pipes such as Linux."
but MacOS has simply not implemented the function (or yes: they return -1 thus) if I've seen correctly. In that case we would need to either : use something else than regular semaphore for this OS. or else: maintain the count ourself (also limited to this case/OS) (but that would require a (preferably) dedicated Lock with each Semaphore).
Activity
remilapeyre commentedon May 27, 2020
The threading.Semaphore class does not have this method, it is undocumented and useless on some system (at least MacOS):
>>> s.get_value() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/synchronize.py", line 129, in get_value return self._semlock._get_value() NotImplementedErrorThe implementation is at https://github.com/python/cpython/blob/master/Modules/_multiprocessing/semaphore.c#L537-L553
I think this method could be removed, since it's undocumented and probably not used can I just remove it or does it need a deprecation cycle?
gst commentedon Nov 7, 2023
why could not the method be simply documented ?
I'm using it already :)
platobms commentedon Nov 7, 2023
I concur with @gst . Was this never intended to be officially supported or was it just implemented only for certain systems (and thus not yet documented)?
It appears to not function on macOS (not implemented) but does work on Linux (x86/Python3.8 and ARM64/Python3.6).
gst commentedon Nov 7, 2023
given it's a public method and has been present for long (always?) and has a well defined and valuable purpose : it should be documented IMHO.
pitrou commentedon Nov 7, 2023
If you manage to make it work cross-platform and make sure tests are present for it, then we could probably document it officially as well.
platobms commentedon Nov 7, 2023
Thanks, makes sense to add tests before promoting it officially.
Regarding cross-platform support, is there a reason that the method can't just apply for OSes which support the necessary underlying C functions? For example (and understandably) different start methods are supported with a comment in the documentation: "Available on POSIX platforms which support passing file descriptors over Unix pipes such as Linux."
pitrou commentedon Nov 7, 2023
We could do that as well. However, it would make sense to first check if support can be added for the missing platforms.
gst commentedon Nov 8, 2023
So you only speak about MacOS, right ?
but MacOS has simply not implemented the function (or yes: they return -1 thus) if I've seen correctly. In that case we would need to either : use something else than regular semaphore for this OS. or else: maintain the count ourself (also limited to this case/OS) (but that would require a (preferably) dedicated Lock with each Semaphore).
I remind sem_getvalue is POSIX after all :)
multiprocessing.[Bounded]Semaphore.get_valuemethod and refactor code #133146