Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-40513: _xxsubinterpreters.run_string() releases the GIL
In the experimental isolated subinterpreters build mode,
_xxsubinterpreters.run_string() now releases the GIL.
  • Loading branch information
vstinner committed May 5, 2020
commit c1a82e59e270abf73242505d585d1ef75ce3d8a1
15 changes: 15 additions & 0 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,20 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
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.
PyThreadState *save_tstate = NULL;
if (interp != PyInterpreterState_Get()) {
Expand All @@ -1956,6 +1970,7 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
if (save_tstate != NULL) {
PyThreadState_Swap(save_tstate);
}
#endif

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