-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-126434: Use RLock for multiprocessing Event to avoid deadlock when handle system signal #126437
base: main
Are you sure you want to change the base?
Conversation
… being called from signal handler
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM
BTW this PR title need be changed
Misc/NEWS.d/next/Library/2024-11-05-11-11-29.gh-issue-126434.Hw3wdI.rst
Outdated
Show resolved
Hide resolved
…w3wdI.rst Co-authored-by: Nadeshiko Manju <[email protected]>
I've changed the title @Zheaoli . What do you think? Thanks again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -0,0 +1 @@ | |||
Use RLock for :mod:`multiprocessing` ``Event`` to avoid deadlock when handle system signal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RLock for :mod:`multiprocessing` ``Event`` to avoid deadlock when handle system signal | |
Use :class:`multiprocessing.RLock` for :class:`multiprocessing.Event` to avoid deadlock when handle system signal |
This patch is failed in free threading TSAN test. need to figure out the root cause |
This test seems to fail in other PRs as well, I restarted the job again to see if it fails again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Event
implementation is not correct with an RLock because that allows reentrancy (from the same thread) during operations that are not written to be reentrant. For example:
def is_set(self):
with self._cond:
if self._flag.acquire(False):
self._flag.release()
return True
return False
After the self._flag.acquire(False)
before the self._flag.release()
, reentrant is_set()
calls will incorrectly appear to be false.
Event
is not written to be safely called from a Python signal handler.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
If this is the origin design behavior. Should we update the docs? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a test, anyway.
Please see issue #126434 for details about bug and code to reproduce deadlock.
Kind regards.