[Question] Consequence of broken semaphore on OSX?
See original GitHub issueHello, this is not an issue, but I’m simply trying to understand the consequences of this warning that appears on OSX (due to the missing sem_getvalue function):
loky/backend/semlock.py:217: RuntimeWarning: semaphore are broken on OSX, release might increase its maximal value
import time
from loky import ProcessPoolExecutor
def f(x):
time.sleep(6)
return x*x
if __name__ == '__main__':
with ProcessPoolExecutor(max_workers=3) as executor:
print("Started")
results = executor.map(f, [1, 2, 3])
print(list(results))
print("Ended")
What is the worse case outcome of this warning?
I also noticed that I could change process_executor.py to use a queue_size of 1 to avoid the warning:
# Finally setup the queues for interprocess communication
self._setup_queues(job_reducers, result_reducers, 1) #force a queue_size of 1
But I’m not sure what that would mean in terms of performance.
Love the work by the way, keep it up! ❤️
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
sem_getvalue() dysfunctionality in Mac OS X - C++
First (and best, in my opinion) redesign your program so that the current value of the semaphore is never needed. After all, as...
Read more >MacOS doesn't support unnamed POSIX semaphores - GitLab
No tasks are currently assigned. Use tasks to break down this issue into smaller parts. Linked items. 0.
Read more >Why does OS X not support unnamed semaphores? - Quora
The reason is that suspension of a process or thread needs support from the OS, unless you accept either high wake operation latency...
Read more >Semaphores - cs.wisc.edu
Let us assume we have five, one for each fork: sem t forks[5]. Broken Solution. We attempt our first solution to the problem....
Read more >Poll on macOS 10.12 is broken - Hacker News
Yeah, Posix semaphores don't work on macOS. Confusingly, support for unnamed semaphores exists however in Apple's libdispatch, using ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The consequence of the broken semaphore on OSX is that we are not able to guarantee that the size of the
ProcessPoolExecutor._call_queuewill stay the same, except whenqueue_size=1.Indeed, the semaphore is an atomic counter, that you can increase or decrease atomically and which blocks in 0. If a
threadtries to decrease it when it is 0, it waits until anotherthreadincreases it. The semaphore have an upper bound which isMAX_SEM_VALUE, depending on your OS.When we define a semaphore in
loky, we give a maximal valuemax_value, which can be lower than the globalMAX_SEM_VALUE. We usesem_get_valueto make sure we do not exceed this value. As this function is not implemented on OSX, we have no guarantees when releasing that we won’t increase the value of the semaphore overmax_value. This is not a problem ifmax_value = MAX_SEM_VALUE, as the OS semaphores handle the case. But this means that there is noBoundedSemaphorein OSX.If you are using the
loky.ProcessPoolExecutor, this is not a big concern. The semaphore withmax_value > 1is the one controlling the size of thecall_queue. On OSX, all the jobs will be en-queued at once, as the size of theQueueis not enforced. The size of theQueueis limited inProcessPoolExecutorin order to allow you to cancel jobs. On OSX, you won’t be able to cancel jobs because as soon as you submit them, they will be put in queue and thus consideredrunning. Theconcurrent.futuresAPI does not permit to killrunningFutures. If you have no need to cancel jobs, you can ignore thisWarning.Note that setting
queue_size=1is a bad idea for performances, as you will get acall_queueof size 1. This means that yourexecutorwill not have any buffer and your workers will be underfed.This issue is inherent to OSX and does not depend on python version. OS X does not implement the function
sem_getvaluewhich is optional in the POSIX standard. The warning only appears in python2 because we use a different implementation of the semaphores.The behavior will not change unless OS X implement the primitive, or we try to come up with a platform specific fix, maybe using SysV semaphores and semctl.