mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
bpo-40513: _xxsubinterpreters.run_string() releases the GIL (GH-19944)
In the experimental isolated subinterpreters build mode, _xxsubinterpreters.run_string() now releases the GIL.
This commit is contained in:
parent
7be4e350aa
commit
fb2c7c4afb
1 changed files with 15 additions and 0 deletions
|
|
@ -1939,6 +1939,20 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
|
||||||
|
// Switch to interpreter.
|
||||||
|
PyThreadState *new_tstate = PyInterpreterState_ThreadHead(interp);
|
||||||
|
PyThreadState *save1 = PyEval_SaveThread();
|
||||||
|
|
||||||
|
(void)PyThreadState_Swap(new_tstate);
|
||||||
|
|
||||||
|
// Run the script.
|
||||||
|
_sharedexception *exc = NULL;
|
||||||
|
int result = _run_script(interp, codestr, shared, &exc);
|
||||||
|
|
||||||
|
// Switch back.
|
||||||
|
PyEval_RestoreThread(save1);
|
||||||
|
#else
|
||||||
// Switch to interpreter.
|
// Switch to interpreter.
|
||||||
PyThreadState *save_tstate = NULL;
|
PyThreadState *save_tstate = NULL;
|
||||||
if (interp != PyInterpreterState_Get()) {
|
if (interp != PyInterpreterState_Get()) {
|
||||||
|
|
@ -1956,6 +1970,7 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
|
||||||
if (save_tstate != NULL) {
|
if (save_tstate != NULL) {
|
||||||
PyThreadState_Swap(save_tstate);
|
PyThreadState_Swap(save_tstate);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Propagate any exception out to the caller.
|
// Propagate any exception out to the caller.
|
||||||
if (exc != NULL) {
|
if (exc != NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue