Author vilya
Recipients vilya
Date 2011-10-28.11:27:57
SpamBayes Score 3.34354e-10
Marked as misclassified No
Message-id <1319801278.56.0.946220269602.issue13285@psf.upfronthosting.co.za>
In-reply-to
Content
The signal module is oblivious to any changes to the set of installed signal handlers which occur outside of the module. This can happen when a native module changes a signal handler, or when the python interpreter is embedded in another program which installs its own signal handlers.

In this case, saving and restoring a signal handler through python doesn't work correctly. For example, if the SIGINT handler is set externally after the signal module is initialised, the following code will replace the external signal handler with python's default_int_handler:

  handler = signal.getsignal(signal.SIGINT)
  signal.signal(signal.SIGINT, handler)

So it's impossible to reliably save and restore signal handlers through python when they can also be changed outside the python interpreter.

Also, if there's a signal handler installed before the module is initialised, signal.getsignal() will return None for it - making it impossible to restore the correct handler after disabling it.

The reason is that the signal module only checks for existing handlers when it's initialised. The results get stored in the Handlers array, which is then used by all subsequent calls to signal.getsignal(). There are no further checks to see whether the native signal handlers have changed.
History
Date User Action Args
2011-10-28 11:27:58vilyasetrecipients: + vilya
2011-10-28 11:27:58vilyasetmessageid: <1319801278.56.0.946220269602.issue13285@psf.upfronthosting.co.za>
2011-10-28 11:27:57vilyalinkissue13285 messages
2011-10-28 11:27:57vilyacreate