summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-01-19 23:04:14 (GMT)
committerGitHub <noreply@github.com>2023-01-19 23:04:14 (GMT)
commit6036c3e856f033bf13e929536e7bf127fdd921c9 (patch)
tree2e0f92c60f4d860826e6e224e6c073e220d76386 /Python/pylifecycle.c
parent8a2d4f4e8eea86352de37d2ce28117e13b3dfaed (diff)
downloadcpython-6036c3e856f033bf13e929536e7bf127fdd921c9.zip
cpython-6036c3e856f033bf13e929536e7bf127fdd921c9.tar.gz
cpython-6036c3e856f033bf13e929536e7bf127fdd921c9.tar.bz2
gh-59956: Clarify GILState-related Code (gh-101161)
The objective of this change is to help make the GILState-related code easier to understand. This mostly involves moving code around and some semantically equivalent refactors. However, there are a also a small number of slight changes in structure and behavior: * tstate_current is moved out of _PyRuntimeState.gilstate * autoTSSkey is moved out of _PyRuntimeState.gilstate * autoTSSkey is initialized earlier * autoTSSkey is re-initialized (after fork) earlier https://github.com/python/cpython/issues/59956
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 1cb0e4d..5ef2d3f 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -675,12 +675,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
const PyConfig *src_config,
PyThreadState **tstate_p)
{
- /* Auto-thread-state API */
- PyStatus status = _PyGILState_Init(runtime);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
-
+ PyStatus status;
PyInterpreterState *interp = PyInterpreterState_New();
if (interp == NULL) {
return _PyStatus_ERR("can't make main interpreter");
@@ -692,6 +687,12 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return status;
}
+ /* Auto-thread-state API */
+ status = _PyGILState_Init(interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
const _PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
init_interp_settings(interp, &config);
@@ -1795,10 +1796,8 @@ finalize_interp_clear(PyThreadState *tstate)
static void
finalize_interp_delete(PyInterpreterState *interp)
{
- if (_Py_IsMainInterpreter(interp)) {
- /* Cleanup auto-thread-state */
- _PyGILState_Fini(interp);
- }
+ /* Cleanup auto-thread-state */
+ _PyGILState_Fini(interp);
/* We can't call _PyEval_FiniGIL() here because destroying the GIL lock can
fail when it is being awaited by another running daemon thread (see