-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-80406: Finalise subinterpreters in Py_FinalizeEx() #17575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
23af5f5
433663c
48e1cfc
0400634
b79649c
8b1e7d9
fd6073a
4bbd58f
1095e66
675285d
8e21788
606c068
e0789b0
dda99ce
847e8d2
a2fb0fc
d234528
46a8619
c89c0e5
c285f52
95cbfd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1257,6 +1257,20 @@ Py_FinalizeEx(void) | |
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime); | ||
PyInterpreterState *interp = tstate->interp; | ||
|
||
// Finalize sub-interpreters. | ||
runtime->interpreters.finalizing = 1; | ||
LewisGaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyInterpreterState *subinterp = PyInterpreterState_Head(); | ||
LewisGaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyInterpreterState *next_interp; | ||
while (subinterp != NULL) { | ||
next_interp = PyInterpreterState_Next(subinterp); | ||
if (subinterp != PyInterpreterState_Main()) { | ||
LewisGaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyThreadState_Swap(subinterp->tstate_head); | ||
Py_EndInterpreter(subinterp->tstate_head); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm yes, do you have any further thoughts on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to give it more thought (and take the time to queue up details into my mental cache 😄). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've recently hit this problem with lingering subinterpreter with existing frames. I solved it by adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ericsnowcurrently any new thoughts here? We might be better off having a call to chat through everything :) |
||
} | ||
subinterp = next_interp; | ||
} | ||
PyThreadState_Swap(tstate); | ||
|
||
// Wrap up existing "threading"-module-created, non-daemon threads. | ||
wait_for_thread_shutdown(tstate); | ||
|
||
|
@@ -1454,6 +1468,10 @@ new_interpreter(PyThreadState **tstate_p) | |
return _PyStatus_ERR("Py_Initialize must be called first"); | ||
} | ||
|
||
if (runtime->interpreters.finalizing) { | ||
LewisGaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return _PyStatus_ERR("Interpreters are being finalized"); | ||
} | ||
|
||
/* Issue #10915, #15751: The GIL API doesn't work with multiple | ||
interpreters: disable PyGILState_Check(). */ | ||
_PyGILState_check_enabled = 0; | ||
|
Uh oh!
There was an error while loading. Please reload this page.