[docs] [issue25666] Python unexpectedly ignores a signal after fork

Martin Panter report at bugs.python.org
Thu Nov 19 20:58:19 EST 2015


Martin Panter added the comment:

Here is a modified version of the script that is not a slow fork bomb. In the original, if time.sleep(600) fails to be interrupted, the children end up continuing the loop and forking more children.

I tried Python 3.5, 2.7 and 3.4. I am seeing the signal completely ignored (at the Python level), not just ignored “for a short while”. Here is a sample output:

$ python3 example.py
Python handler called
Parent waiting for child
Got exit status 0x0000
===
Parent waiting for child
Child: 0
Child: 1
Child: 2
Child: 3
Child: 4
Child: 5
Got exit status 0x0100

David may be right that it is an OS thing, though it does not seem likely IMO. It needs more investigation or expert knowledge.

But I would like to point out that even if the bug of the signal being completely ignored is fixed, the code still has a race condition. The signal could arrive in the window between when Python checks for signals and when it calls sleep(). Then the signal will be ignored until sleep() has returned. If you need this code to be robust, I suggest looking at set_signal_fd() and select().

----------
nosy: +martin.panter
versions: +Python 3.5, Python 3.6
Added file: http://bugs.python.org/file41089/example.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25666>
_______________________________________


More information about the docs mailing list