Issue #3137: Don't ignore errors at startup, especially a keyboard interrupt
(SIGINT). If an error occurs while importing the site module, the error is
printed and Python exits. Initialize the GIL before importing the site
module.
diff --git a/Modules/main.c b/Modules/main.c
index 1511dd9..7f98ed0 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -573,10 +573,16 @@
}
if (sts==-1) {
- sts = PyRun_AnyFileExFlags(
- fp,
- filename == NULL ? "<stdin>" : filename,
- filename != NULL, &cf) != 0;
+ /* call pending calls like signal handlers (SIGINT) */
+ if (Py_MakePendingCalls() == -1) {
+ PyErr_Print();
+ sts = 1;
+ } else {
+ sts = PyRun_AnyFileExFlags(
+ fp,
+ filename == NULL ? "<stdin>" : filename,
+ filename != NULL, &cf) != 0;
+ }
}
}