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

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Jan 24 12:22:09 CET 2007


On Tue, Jan 23, 2007, Ulisses Furquim wrote:
>
> I've read some threads about signals in the archives and I was under
> the impression signals should work reliably on single-threaded
> applications. Am I right?  I've thought about a way to fix this, but I
> don't know what is the current plan for signals support in python, so
> what can be done?

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.  Inter alia, all of the following are
likely to lead to lost signals:

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'.

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

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.)

And there is more, some of which can cause program misbehaviour or
crashes.  You are also right that threading makes the situation a
lot worse.

Obviously, Unix and Microsoft systems depend on signals, so you
can't simply regard them as hopelessly broken, but you can't assume
that they are RELIABLE.  All code should be designed to cope with
the case of signals getting lost, if at all possible.  Defending
yourself against the other failures is an almost hopeless task,
but luckily they are extremely rare except on specialist systems.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679


More information about the Python-Dev mailing list