[issue29926] IDLE: in shell, time.sleep ignores _thread.interrupt_main()

Antoine Pitrou report at bugs.python.org
Fri Jun 30 03:46:22 EDT 2017


Antoine Pitrou added the comment:

Please step back a bit and read the implementation of interrupt_main(): it calls PyErr_SetInterrupt() (in signalmodule.c!), which merely sets an internal flag saying SIGINT was received.

So, there: PyErr_SetInterrupt() already behaves like SIGINT, *except* that it doesn't actually deliver a C signal, it merely sets a flag.  Which is the reason that it fails waking up C syscalls like select().

Demonstration:

>>> def handler(signum, frame):
...     print("got signal %d!" % (signum,))
... 
>>> signal.signal(signal.SIGINT, handler)
<built-in function default_int_handler>
>>> _thread.interrupt_main()
got signal 2!


In the end, making interrupt_main() *actually* deliver a SIGINT instead of merely setting the internal flag for it will certainly be true to the original intent.

----------

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


More information about the Python-bugs-list mailing list