[Python-checkins] Re-init _Py_UnhandledKeyboardInterrupt before run. (GH-11963)

Gregory P. Smith webhook-mailer at python.org
Wed Feb 20 20:35:59 EST 2019


https://github.com/python/cpython/commit/d9bc543cbb9681f77d94864d05e2ba2d353e6de9
commit: d9bc543cbb9681f77d94864d05e2ba2d353e6de9
branch: master
author: Gregory P. Smith <greg at krypto.org>
committer: GitHub <noreply at github.com>
date: 2019-02-20T17:35:54-08:00
summary:

Re-init _Py_UnhandledKeyboardInterrupt before run. (GH-11963)

Explicitly reinitialize this every eval *just in case* someone is
calling into an embedded Python where they don't care about an uncaught
KeyboardInterrupt exception (why didn't they leave
`config.install_signal_handlers` set to `0`?!?) but then later call
`Py_Main()` itself (which *checks* this flag and dies with a signal after
its interpreter exits).  We don't want a previous embedded interpreter's
uncaught exception to trigger an unexplained signal exit from a future
`Py_Main()` based one.

files:
M Python/pythonrun.c

diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 94fcc6725ec4..906877a0a853 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1032,6 +1032,17 @@ static PyObject *
 run_eval_code_obj(PyCodeObject *co, PyObject *globals, PyObject *locals)
 {
     PyObject *v;
+    /*
+     * We explicitly re-initialize _Py_UnhandledKeyboardInterrupt every eval
+     * _just in case_ someone is calling into an embedded Python where they
+     * don't care about an uncaught KeyboardInterrupt exception (why didn't they
+     * leave config.install_signal_handlers set to 0?!?) but then later call
+     * Py_Main() itself (which _checks_ this flag and dies with a signal after
+     * its interpreter exits).  We don't want a previous embedded interpreter's
+     * uncaught exception to trigger an unexplained signal exit from a future
+     * Py_Main() based one.
+     */
+    _Py_UnhandledKeyboardInterrupt = 0;
     v = PyEval_EvalCode((PyObject*)co, globals, locals);
     if (!v && PyErr_Occurred() == PyExc_KeyboardInterrupt) {
         _Py_UnhandledKeyboardInterrupt = 1;



More information about the Python-checkins mailing list