Automatically restarting system calls?

Hrvoje Niksic hniksic at xemacs.org
Mon Jun 16 08:59:19 CEST 2008


Rhamphoryncus <rhamph at gmail.com> writes:

> You might find a way to get SA_RESTART applied, but it won't work
> right for you.  Python splits signal handlers into a top half and a
> bottom half - the bottom is in C, it's the real signal handler, and
> top is in python.  To keep things sane for the top half, it delays
> until the interpreter is in a sane state (such as between
> bytecodes).  If you used SA_RESTART the bottom half would still
> work, but the top would be delayed indefinitely until something else
> woke up the interpreter.  In other words, your window likely won't
> redraw until the user types something or you print something.

One possible way to handle this is by implementing a small signal
handler in C.  This signal handler can set the signal using
SA_RESTART, getting rid of EINTR, at least for popular syscalls.  In
the signal handler it can simply write a byte into a pipe, the other
end of which is monitored by the select() event loop.  Python,
presumably sleeping in select(), or about to do that, will immediately
notice the "signal" by the pipe becoming readable.



More information about the Python-list mailing list