diff options
author | Victor Stinner <vstinner@python.org> | 2020-05-05 18:33:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 18:33:06 (GMT) |
commit | fb2c7c4afbab0514352ab0246b0c0cc85d1bba53 (patch) | |
tree | 0894e024e670aefdfe4d42c828a9628b1354dcce | |
parent | 7be4e350aadf93c4be5c97b7291d0db2b6bc1dc4 (diff) | |
download | cpython-fb2c7c4afbab0514352ab0246b0c0cc85d1bba53.zip cpython-fb2c7c4afbab0514352ab0246b0c0cc85d1bba53.tar.gz cpython-fb2c7c4afbab0514352ab0246b0c0cc85d1bba53.tar.bz2 |
bpo-40513: _xxsubinterpreters.run_string() releases the GIL (GH-19944)
In the experimental isolated subinterpreters build mode,
_xxsubinterpreters.run_string() now releases the GIL.
-rw-r--r-- | Modules/_xxsubinterpretersmodule.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index de11c09..8a6fce9 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -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()) { @@ -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) { |