gh-125828 : Fix 'get_value' missing for [Bounded]Semaphore on multiprocessing MacOSX - C workaround #130913
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following #125829 discussions and after a long deeping in the
_multiprocessing.semaphore.c
C file, I suggest a workaround based on a shared memory that contains an array to store all the internal semaphore counters.At the moment, all the tests are passing, but I'm having 2 side problems, the second of which is really embarrassing:
sysconf(SC_SEM_NSEMS_MAX)
which is set to 87381 on a mac OSX 15. This is very high.shm_unlink
to properly close the shared memory (First I calledshm_open
)?Regarding this last point, I wonder if only the process that opened the shared memory should call this function? Or should all processes that called
shm_open
callshm_unlink
? Unfortunately, the Posix documentation isn't precise.I worked on the count of opened/closed processes, with the aim of calling
shm_unlink
when the last process has closed, without success. I also had a look to theposixshmem
module, without success too.Could the
resource_tracker
and/or the use of theFinalize
class of themultiprocessing.util
module help me to fix this problem ? Is it possible to use these 2 Python libs from C API ?This memory management difficulty make me think that this choice may not be appropriate. I am a bit stuck.
Thank you for your feedback and ideas.