cpython
cpython copied to clipboard
gh-125828 : Fix 'get_value' missing on [Bouded]Semaphore on multiprocessing MacOSX
This proposal is a workaround to fix absence of 'sem_getvalue' C function in the Semaphore MacOSX implementation.
Alls unit tests succeed except on test.test_concurrent_futures.test_init relative to the Resource Tracker manager.
- Issue: gh-125828
This needs a NEWS entry :)
Is get_value part of the public API for these classes? The name suggests it is, but the method is not document in the reference docs and does not have a docsstring.
I haven't looked with enough detail at the code to be certain, and am not a multiprocessing expert, but I the code doesn't seem correct. In particular, how does the implementation handle blocking callers of acquire when the count is 0 but not when it is larger than 0?
is
get_valuepart of the public API for these classes? The name suggests it is, but the method is not document in the reference docs and does not have a docsstring.
Yes, it is and I confirm this is not documented. This public method is rarely used to get a value of semaphore, except in unit tests. I should open an issue about this case.
In particular, how does the implementation handle blocking callers of acquire when the count is 0 but not when it is larger than 0?
As I explain it above, this class only listen to acquire and release to update shared counter and then call respectively acquire and releasemethods of _semlock class. When get_value is invoked, the class returns the counter value, and never calls the semlock._get_value method (which raises NotImplementedError).
In this way, the behaviour of semaphores is always done at a low level in the implementation of the semlockclass in the semaphore module (at C level).