A note to signal.signal() usage

I 'd like to propose adding a note to the signal.signal() documentation reminding users of a possible issue, albeit quite rare.

The signal.signal() is a low-level function for setting a new signal disposition. If a signal handler (i.e. a callable function) was installed already e.g. by a 3rd party library or by the Python interpreter itself, installing a new handler replaces it. If it is not intended, it will probably break something.

The proper way is to check the previous disposition (the value returned by signal.signal) and if it is callable (i.e. not SIG_IGN nor SIG_DFL), the newly installed handler should call it. Multiple handlers should build a chain.

I’m not a native speaker. Here is something short to start with. Feel free to to use any better sentence.

Note: After installing a handler function, any previously installed handler function will be replaced, not chained.

1 Like