https://github.com/python/cpython/commit/468430189d3ebe16f3067279f9be0fe82cdfadf6
commit: 468430189d3ebe16f3067279f9be0fe82cdfadf6
branch: main
author: Eric Snow <[email protected]>
committer: ericsnowcurrently <[email protected]>
date: 2024-02-14T16:07:22-07:00
summary:

gh-115482: Assume the Main Interpreter is Always Running "main" (gh-115484)

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.

files:
M Python/pystate.c

diff --git a/Python/pystate.c b/Python/pystate.c
index 82c955882185e8..08ec586963ce11 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to