[Python-Dev] Problem with signals in a single threaded application

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jan 27 02:35:21 CET 2007


Nick Maclaren wrote:

> This one looks like an oversight in Python code, and so is a bug,
> but it is important to note that signals do NOT work reliably under
> any Unix or Microsoft system.

That's a rather pessimistic way of putting it. In my
experience, signals in Unix mostly do what they're
meant to do quite reliably -- it's just a matter of
understanding what they're meant to do.

There may be bugs in certain systems that cause
signals to get lost under obscure circumstances, but
that's no reason for Python to make the situation
worse by introducing bugs of its own.

> Two related signals received between two 'checkpoints' (i.e. when
> the signal is tested and cleared).  You may only get one of them,
> and 'related' does not mean 'the same'.

In the case where they're the same, I wouldn't
say that the second signal has been "lost". Rather,
it's simply redundant -- a call to the handler is
already pending, and will happen eventually. (If
you're expecting one call per signal, then you're
using the wrong mental model for signals.)

I wasn't aware that this could happen between
different signals. If it can, there must be some
rationale as to why the second signal is considered
redundant. Otherwise there's a bug in either the
design or the implementation.

> A second signal received while the first is being 'handled' by the
> operating system or language run-time system.

That one sounds odd to me. I would expect a signal
received during the execution of a handler to be
flagged and cause the handler to be called again
after it returns. But then I'm used to the BSD
signal model, which is relatively sane.

> A signal sent while the operating system is doing certain things to
> the application (including, sometimes, when it is swapped out or
> deep in I/O.)

That sounds like an outright bug. I can't think
of any earthly reason why the handler shouldn't
be called eventually, if it remains installed and
the process lives long enough.

--
Greg



More information about the Python-Dev mailing list