[New-bugs-announce] [issue23395] _thread.interrupt_main() errors if SIGINT handler in SIG_DFL, SIG_IGN

Thomas Kluyver report at bugs.python.org
Thu Feb 5 00:50:50 CET 2015


New submission from Thomas Kluyver:

In tracking down an obscure error we were seeing, we boiled it down to this test case for thread.interrupt_main():

import signal, threading, _thread, time
signal.signal(signal.SIGINT, signal.SIG_DFL) # or SIG_IGN

def thread_run():
    _thread.interrupt_main()

t = threading.Thread(target=thread_run)
t.start()
time.sleep(10)

This fails with an error message "TypeError: 'int' object is not callable", and a traceback completely disconnected from the cause of the error, presumably because it's not coming from the usual Python stack.

The problem appears to be that interrupt_main sets (in the C code) Handlers[SIGINT].tripped, which is only expected to occur when the handler is a Python function. When PyErr_CheckSignals() runs, it tries to call Handlers[SIGINT].func as a Python function, but it's a Python integer, causing the error.

I think the fix for this is to check what Handlers[sig_num].func is, either in trip_signal() before setting Handlers[sig_num].tripped, or in PyErr_CheckSignals before calling it. I can work on a patch if desired, but I'm not brilliant at C.

----------
components: Library (Lib)
messages: 235412
nosy: minrk, takluyver
priority: normal
severity: normal
status: open
title: _thread.interrupt_main() errors if SIGINT handler in SIG_DFL, SIG_IGN
type: behavior
versions: Python 3.5

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


More information about the New-bugs-announce mailing list