cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-125828 : Fix 'get_value' missing on [Bouded]Semaphore on multiprocessing MacOSX

Open YvesDup opened this issue 1 year ago • 1 comments

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

YvesDup avatar Oct 22 '24 07:10 YvesDup

This needs a NEWS entry :)

ZeroIntensity avatar Oct 23 '24 16:10 ZeroIntensity

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?

ronaldoussoren avatar Oct 25 '24 11:10 ronaldoussoren

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.

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).

YvesDup avatar Nov 04 '24 13:11 YvesDup