New submission from Ronald Li <ronald.ch...@gmail.com>:
The attached script ign2ndsig.py demonstrates an attempted way to handle signals at most once and ignore any subsequent signals. SIGINT and SIGTERM are used in the demo. In Python 3.5, the subprocess would go into one of the "except KeyboardInterrupt:" or "except SystemExit:" blocks before doing "finally:" and exiting zero: # execute the script with no args: # ./ign2ndsig.py subproc: sys.version_info(major=3, minor=5, micro=9, releaselevel='final', serial=0) raising KeyboardInterrupt handling KeyboardInterrupt doing finally rc: 0 In Python 3.6, 3.7 or 3.8, the subprocess would go into neither the "except KeyboardInterrupt:" nor "except SystemExit:" blocks before doing "finally:" and exiting non-zero, with a traceback like this: subproc: sys.version_info(major=3, minor=6, micro=10, releaselevel='final', serial=0) raising KeyboardInterrupt doing finally Traceback (most recent call last): File "./ign2ndsig.py", line 30, in subproc input() File "./ign2ndsig.py", line 18, in handler raise KeyboardInterrupt KeyboardInterrupt During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./ign2ndsig.py", line 58, in <module> subproc() File "./ign2ndsig.py", line 32, in subproc printef('handling KeyboardInterrupt') File "./ign2ndsig.py", line 10, in printef print(*objects, file=sys.stderr, flush=True) TypeError: 'int' object is not callable rc: 1 More on the behaviors of ign2ndsig.py : 1. Replacing SIG_IGN at line 14 and 15 with a no-op Python function "fixes" the problem - such that in Python 3.6, 3.7 or 3.8, it'd behave similarly to the Python 3.5 output above. 2. Sending a SIGTERM then a SIGINT (instead of a SIGINT followed by a SIGTERM) (i.e. reversing the order of SIGINT and SIGTERM) at line 49-50 results in a similar behavior (that the TypeError is raised). 3. Sending 2 SIGINTs or 2 SIGTERMs (instead of 1 SIGINT + 1 SIGTERM) (i.e. sending the same signal twice) at line 49-50 does NOT result in the TypeError. Potentially related issues: _thread.interrupt_main() errors if SIGINT handler in SIG_DFL, SIG_IGN https://bugs.python.org/issue23395 Turn SIG_DFL and SIG_IGN into functions https://bugs.python.org/issue23325 ---------- files: ign2ndsig.py messages: 359071 nosy: Ronald Li priority: normal severity: normal status: open title: TypeError: 'int' object is not callable if the signal handler is SIG_IGN type: behavior versions: Python 3.6, Python 3.7, Python 3.8 Added file: https://bugs.python.org/file48810/ign2ndsig.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39169> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com