multiprocessing.Event.set() can be deadlocked by .is_set when called by a sigterm handler #126434
Labels
stdlib
Python modules in the Lib dir
topic-multiprocessing
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
multiprocessing.Event.set()
will acquire a lock when setting the internal flag.multiprocessing.Event.is_set()
will acquire the same lock when checking the flag. Thus if a signal handler calls.set()
when.is_set()
is running on the same process, there will be a deadlock.multiprocessing.Event
uses a regular non-reentrantlock lock. This should be changed to a reentrant lock. Please see the pull request.Thanks for all the work on the Python programming language. I appreciate all your efforts highly.
Kind regards.
Example program below that (sometimes) deadlocks. On my machine I typically need to run it less than 10 times before a deadlock occurs. Also included in the code block is a sample stacktrace.
CPython versions tested on:
3.11, 3.12, CPython main branch
Operating systems tested on:
Linux, macOS
Linked PRs
The text was updated successfully, but these errors were encountered: