Skip to content

Commit d9bc543

Browse files
authored
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.
1 parent 9b0c681 commit d9bc543

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Python/pythonrun.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,17 @@ static PyObject *
10321032
run_eval_code_obj(PyCodeObject *co, PyObject *globals, PyObject *locals)
10331033
{
10341034
PyObject *v;
1035+
/*
1036+
* We explicitly re-initialize _Py_UnhandledKeyboardInterrupt every eval
1037+
* _just in case_ someone is calling into an embedded Python where they
1038+
* don't care about an uncaught KeyboardInterrupt exception (why didn't they
1039+
* leave config.install_signal_handlers set to 0?!?) but then later call
1040+
* Py_Main() itself (which _checks_ this flag and dies with a signal after
1041+
* its interpreter exits). We don't want a previous embedded interpreter's
1042+
* uncaught exception to trigger an unexplained signal exit from a future
1043+
* Py_Main() based one.
1044+
*/
1045+
_Py_UnhandledKeyboardInterrupt = 0;
10351046
v = PyEval_EvalCode((PyObject*)co, globals, locals);
10361047
if (!v && PyErr_Occurred() == PyExc_KeyboardInterrupt) {
10371048
_Py_UnhandledKeyboardInterrupt = 1;

0 commit comments

Comments
 (0)