| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
|
||
| Because lock acquisition can be interrupted by signals, sharing reentrant | ||
| locks between :mod:`signal` handlers and the main thread can lead to | ||
| surprising behavior. Therefore, this is generally not recommended. |
There was a problem hiding this comment.
surprising behavior
any other surprise that is not main thread waiting forever for itself to release RLock?
Sorry, something went wrong.
There was a problem hiding this comment.
I think the note should go at the top of the file as a general warning about concurrency and signal handlers.
Sorry, something went wrong.
| Because lock acquisition can be interrupted by signals, sharing reentrant | ||
| locks between :mod:`signal` handlers and the main thread can lead to | ||
| surprising behavior. Therefore, this is generally not recommended. |
There was a problem hiding this comment.
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
There was a problem hiding this comment.
This isn't limited to re-entrant locks.
what is surprising about normal locks (like returned by _thread.allocate_lock())?
Sorry, something went wrong.
There was a problem hiding this comment.
sharing a synchronization primitive between the signal handler and some thread other than the main thread should work just fine, shouldn't it?
I think you're missing the point. It might work right now, but using locks in signal handlers is not something we want to encourage or claim to support. We may want to change how we handle signals or what they affect someday.
what is surprising about normal locks (like returned by _thread.allocate_lock())?
By acquiring a lock in a signal handler, the lock is subject to deadlocks for any signal handled by the main thread. For example:
Sorry, something went wrong.
There was a problem hiding this comment.
I think you're missing the point. It might work right now, but using locks in signal handlers is not something we want to encourage or claim to support. We may want to change how we handle signals or what they affect someday.
Alright. In such case, I think this warning belongs into the signal module instead.
Sorry, something went wrong.
| Synchronization primitives such as :class:`threading.Lock` should not be used | ||
| within signal handlers. Because blocking synchronization calls can be | ||
| interrupted by signals, such usage can lead to surprising dead locks. |
There was a problem hiding this comment.
I don't think we need to be specific:
| Synchronization primitives such as :class:`threading.Lock` should not be used | |
| within signal handlers. Because blocking synchronization calls can be | |
| interrupted by signals, such usage can lead to surprising dead locks. | |
| Synchronization primitives such as :class:`threading.Lock` should not be used | |
| within signal handlers. Doing so can lead to deadlocks. |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for the suggestion. I think if I were to read this for the first time I wouldn't understand the issue. And understanding something makes it easier to remember, too. I'd probably be thinking something like "well yeah, using synchronization primitives in general can lead to deadlocks. So what's different here?"
Sorry, something went wrong.
There was a problem hiding this comment.
Let's say "unexpected deadlocks" then. The situation in the issue is one of many problems that come up when using synchronization primitives in signal handlers, so it's misleading to say that interruptibility is the only concern.
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks, LGTM.
Sorry, something went wrong.
|
Thanks @robsdedude for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
… signal handlers (pythonGH-144736) (cherry picked from commit 945bf8c) Co-authored-by: Robsdedude <dev@rouvenbauer.de>
… signal handlers (pythonGH-144736) (cherry picked from commit 945bf8c) Co-authored-by: Robsdedude <dev@rouvenbauer.de>
|
GH-144767 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
GH-144768 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Document potentially surprising interplay or threading.RLock and signal as discussed in #144706 (comment).
📚 Documentation preview 📚: https://cpython-previews--144736.org.readthedocs.build/