]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-115482: Assume the Main Interpreter is Always Running "main" (gh-115484)
authorEric Snow <ericsnowcurrently@gmail.com>
Wed, 14 Feb 2024 23:07:22 +0000 (16:07 -0700)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2024 23:07:22 +0000 (16:07 -0700)
This is a temporary fix to unblock embedders that do not call Py_Main().

_PyInterpreterState_IsRunningMain() will always return true for the main interpreter, even in corner cases where it technically should not. The (future) full solution will do the right thing in those corner cases.

Python/pystate.c

index 82c955882185e85250235892abaeafa50aac3f81..08ec586963ce114a6ab79655e47df988e5607785 100644 (file)
@@ -1044,7 +1044,14 @@ _PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp)
 int
 _PyInterpreterState_IsRunningMain(PyInterpreterState *interp)
 {
-    return (interp->threads.main != NULL);
+    if (interp->threads.main != NULL) {
+        return 1;
+    }
+    // For now, we assume the main interpreter is always running.
+    if (_Py_IsMainInterpreter(interp)) {
+        return 1;
+    }
+    return 0;
 }
 
 int