summaryrefslogtreecommitdiff
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 705708698c..61f87c5eba 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -591,6 +591,7 @@ init_interp_create_gil(PyThreadState *tstate, int own_gil)
/* finalize_interp_delete() comment explains why _PyEval_FiniGIL() is
only called here. */
+ // XXX This is broken with a per-interpreter GIL.
_PyEval_FiniGIL(tstate->interp);
/* Auto-thread-state API */
@@ -645,7 +646,8 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return _PyStatus_ERR("can't make first thread");
}
_PyThreadState_Bind(tstate);
- (void) PyThreadState_Swap(tstate);
+ // XXX For now we do this before the GIL is created.
+ (void) _PyThreadState_SwapNoGIL(tstate);
status = init_interp_create_gil(tstate, config.own_gil);
if (_PyStatus_EXCEPTION(status)) {
@@ -2025,11 +2027,20 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
}
_PyThreadState_Bind(tstate);
- PyThreadState *save_tstate = PyThreadState_Swap(tstate);
+ // XXX For now we do this before the GIL is created.
+ PyThreadState *save_tstate = _PyThreadState_SwapNoGIL(tstate);
+ int has_gil = 0;
+
+ /* From this point until the init_interp_create_gil() call,
+ we must not do anything that requires that the GIL be held
+ (or otherwise exist). That applies whether or not the new
+ interpreter has its own GIL (e.g. the main interpreter). */
/* Copy the current interpreter config into the new interpreter */
const PyConfig *src_config;
if (save_tstate != NULL) {
+ // XXX Might new_interpreter() have been called without the GIL held?
+ _PyEval_ReleaseLock(save_tstate);
src_config = _PyInterpreterState_GetConfig(save_tstate->interp);
}
else
@@ -2039,11 +2050,13 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
src_config = _PyInterpreterState_GetConfig(main_interp);
}
+ /* This does not require that the GIL be held. */
status = _PyConfig_Copy(&interp->config, src_config);
if (_PyStatus_EXCEPTION(status)) {
goto error;
}
+ /* This does not require that the GIL be held. */
status = init_interp_settings(interp, config);
if (_PyStatus_EXCEPTION(status)) {
goto error;
@@ -2053,6 +2066,7 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
if (_PyStatus_EXCEPTION(status)) {
goto error;
}
+ has_gil = 1;
status = pycore_interp_init(tstate);
if (_PyStatus_EXCEPTION(status)) {
@@ -2072,7 +2086,12 @@ error:
/* Oops, it didn't work. Undo it all. */
PyErr_PrintEx(0);
- PyThreadState_Swap(save_tstate);
+ if (has_gil) {
+ PyThreadState_Swap(save_tstate);
+ }
+ else {
+ _PyThreadState_SwapNoGIL(save_tstate);
+ }
PyThreadState_Clear(tstate);
PyThreadState_Delete(tstate);
PyInterpreterState_Delete(interp);