[issue12060] Python doesn't support real time signals

Charles-François Natali report at bugs.python.org
Fri May 13 01:59:39 CEST 2011


Charles-François Natali <neologix at free.fr> added the comment:

> Evaluate Python code in a signal handler is really not a good idea!

I know, you're limited to async-safe functions, among other things :-)

> because of the GIL, I don't think that we can do better. But with the
> GIL of Python 3.3, the Python signal handler will be called "immediatly"
> before the next instruction, instead of having to wait something like
> 100 Python instructions (sys.getcheckinterval()). On this point, Python
> 3.3 is better than all previous versions.
>

Nice.

> Well, we can imagine to have an option/function to enable real time
> and/or in-order signals (e.g. using pipes).
>
> Can we call this mode "real time"? Real time means that we warranty a
> maximum response time.
>

Well, I think that we should either make this the default behaviour
(that's why I was asking whether it's possible on Windows), or not
implement it. Having two modes for signal handling is confusing.
But given that this behaviour has never been noticed before and that I
doubt that people needing real-time signals use Python (and
vice-versa), maybe we should just stick with the current
implementation, which is safe and simple (see Antoine's question, "Is
it a theoretical concern or does it affect real software?").
On the other hand, if it turns out to be interesting to some people,
I'd be happy to work on a patch.

>> By the way, to be pedantic, in the current code, wakeup_fd and
>> Handlers should be volatile, and tripped should be sig_atomic_t.
>
> Yes. Can you please write a patch for this?

Patch attached.

----------
Added file: http://bugs.python.org/file21989/signal_pedantic.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12060>
_______________________________________
-------------- next part --------------
diff -r 3ebe2d261920 Modules/signalmodule.c
--- a/Modules/signalmodule.c	Thu May 12 16:18:29 2011 +0100
+++ b/Modules/signalmodule.c	Fri May 13 01:11:27 2011 +0200
@@ -88,12 +88,12 @@
 static pid_t main_pid;
 #endif
 
-static struct {
-    int tripped;
+static volatile struct {
+    sig_atomic_t tripped;
     PyObject *func;
 } Handlers[NSIG];
 
-static sig_atomic_t wakeup_fd = -1;
+static volatile sig_atomic_t wakeup_fd = -1;
 
 /* Speed up sigcheck() when none tripped */
 static volatile sig_atomic_t is_tripped = 0;


More information about the Python-bugs-list mailing list