-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
Sending many signals to a Python process crashes the interpreter #118143
Comments
What do you realistically expect to happen? Which behaviors do you think indicate fixable bugs in Python? What possible responses would not be a bug? |
I'm no expert on signals, so my expectations may be weird ("unrealisitic"). Based on the various manuals (not least of which Python's own), I would expect them to be something processes can send to each other to signal something 😄 That such signals may be lost if many are sent is part of my expectations, and is documented for e.g. the Linux platform. However, I do not expect signals to be means of crashing other processes if this is not the explicit goal of the signal (i.e. SIGKILL killing a process is expected). Especially given the fact that the Python manual documents the existence of a Python signal handler, I would expect setting up such a handler would make it so that signals are handled by it. Even if there are many. Not handling the signal (and crashing) is a bug (given my current set of expectations) then. I am not sure whether this is is a "fixable" bug in Python. Let's first determine whether it is a bug at al 😄 |
Another way of saying this is: I expect the program to behave as it behaves when sending "just a few" signals. This to me is an indication that this is a bug: when the load increases, the program fails. In a way that is not predicted by the documentation. |
@gpshead signals issue |
Curiously, the small C program I wrote to handle "many" of these signals is also not able to deal with them successfully:
(based on https://stackoverflow.com/questions/4217037/catch-ctrl-c-in-c) though this is somewhat more stable on my system than the Python version, bombarding it with many signals I am able to let this program "hang" (show no more output and use no more CPU) though not crash. Not sure what to make of this though. |
But taking
So I'm chalking this one up to Python after all |
from C you cannot do IO in a signal handler. In pure python code we run the signal handler code later outside of C signal handler context, thus it may technically be able to do more at times, but I'd still rank "doing IO" even in a python signal handler (which is effectively possible to be executed between any given bytecode and between some operations using the C API that check the internal signal context) as a bad idea. Regardless, if we can prevent 'Exit with "User defined signal 1" (shouldn't happen, we've defined a handler)' from happening that'd be good. If this can be reproduced in a simple handler that does no IO that'd be much more interesting. As for why this may not be a significant problem as is in practice: Signals are generally not frequent. |
I have indeed not been able to reproduce the problem when I adapted the signal handler like so:
This would make me say that this is indeed not a (Python) bug. |
I have recently come to agree with this pov, but perhaps the documentation should be clarified somewhat. Example of a serious project that does quite some IO in its signal handlers: https://github.com/benoitc/gunicorn/blob/master/gunicorn/arbiter.py#L252 (and lines below) |
Bug report
Bug description:
Consider the following simple program (
test-breakage.py
):Now, a tool to send "a lot" of signal to it:
Or, if you want the signals to be sent more quickly, implemented in c:
Running these scripts with "sufficiently high" numbers results in various crashes in
test-breakage
RuntimeError
without any further information(In all cases, after repeating "handle_sigusr1" a number of times first)
tested on Linux w. Python 3.10
CPython versions tested on:
3.10
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: