Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb2c7c4

Browse files
authored
bpo-40513: _xxsubinterpreters.run_string() releases the GIL (GH-19944)
In the experimental isolated subinterpreters build mode, _xxsubinterpreters.run_string() now releases the GIL.
1 parent 7be4e35 commit fb2c7c4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Modules/_xxsubinterpretersmodule.c

+15
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,20 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
19391939
return -1;
19401940
}
19411941

1942+
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
1943+
// Switch to interpreter.
1944+
PyThreadState *new_tstate = PyInterpreterState_ThreadHead(interp);
1945+
PyThreadState *save1 = PyEval_SaveThread();
1946+
1947+
(void)PyThreadState_Swap(new_tstate);
1948+
1949+
// Run the script.
1950+
_sharedexception *exc = NULL;
1951+
int result = _run_script(interp, codestr, shared, &exc);
1952+
1953+
// Switch back.
1954+
PyEval_RestoreThread(save1);
1955+
#else
19421956
// Switch to interpreter.
19431957
PyThreadState *save_tstate = NULL;
19441958
if (interp != PyInterpreterState_Get()) {
@@ -1956,6 +1970,7 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
19561970
if (save_tstate != NULL) {
19571971
PyThreadState_Swap(save_tstate);
19581972
}
1973+
#endif
19591974

19601975
// Propagate any exception out to the caller.
19611976
if (exc != NULL) {

0 commit comments

Comments
 (0)