Skip to content

Commit 3cc9dc3

Browse files
Do not release the GIL when not necessary.
1 parent 85702ae commit 3cc9dc3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Python/pylifecycle.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,10 +2031,14 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
20312031
PyThreadState *save_tstate = _PyThreadState_SwapNoGIL(tstate);
20322032
int has_gil = 0;
20332033

2034+
/* From this point until the init_interp_create_gil() call,
2035+
we must not do anything that requires that the GIL be held
2036+
(or otherwise exist). That applies whether or not the new
2037+
interpreter has its own GIL (e.g. the main interpreter). */
2038+
20342039
/* Copy the current interpreter config into the new interpreter */
20352040
const PyConfig *src_config;
20362041
if (save_tstate != NULL) {
2037-
_PyEval_ReleaseLock(save_tstate);
20382042
src_config = _PyInterpreterState_GetConfig(save_tstate->interp);
20392043
}
20402044
else
@@ -2044,11 +2048,13 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
20442048
src_config = _PyInterpreterState_GetConfig(main_interp);
20452049
}
20462050

2051+
/* This does not require that the GIL be held. */
20472052
status = _PyConfig_Copy(&interp->config, src_config);
20482053
if (_PyStatus_EXCEPTION(status)) {
20492054
goto error;
20502055
}
20512056

2057+
/* This does not require that the GIL be held. */
20522058
status = init_interp_settings(interp, config);
20532059
if (_PyStatus_EXCEPTION(status)) {
20542060
goto error;

0 commit comments

Comments
 (0)