Skip to content

bpo-38070: Add _PyRuntimeState.preinitializing #16245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,20 @@ struct _gilstate_runtime_state {
/* Full Python runtime state */

typedef struct pyruntimestate {
/* Is Python pre-initialized? Set to 1 by Py_PreInitialize() */
int pre_initialized;
/* Is running Py_PreInitialize()? */
int preinitializing;

/* Is Python preinitialized? Set to 1 by Py_PreInitialize() */
int preinitialized;

/* Is Python core initialized? Set to 1 by _Py_InitializeCore() */
int core_initialized;

/* Is Python fully initialized? Set to 1 by Py_Initialize() */
int initialized;

/* Set by Py_FinalizeEx(). Only reset to NULL if Py_Initialize()
is called again. */
PyThreadState *finalizing;

struct pyinterpreters {
Expand Down Expand Up @@ -241,7 +246,7 @@ typedef struct pyruntimestate {
} _PyRuntimeState;

#define _PyRuntimeState_INIT \
{.pre_initialized = 0, .core_initialized = 0, .initialized = 0}
{.preinitialized = 0, .core_initialized = 0, .initialized = 0}
/* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */

PyAPI_DATA(_PyRuntimeState) _PyRuntime;
Expand Down
11 changes: 8 additions & 3 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,15 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
}
_PyRuntimeState *runtime = &_PyRuntime;

if (runtime->pre_initialized) {
if (runtime->preinitialized) {
/* If it's already configured: ignored the new configuration */
return _PyStatus_OK();
}

/* Note: preinitialized remains 1 on error, it is only set to 0
at exit on success. */
runtime->preinitializing = 1;

PyPreConfig config;
_PyPreConfig_InitFromPreConfig(&config, src_config);

Expand All @@ -743,7 +747,8 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
return status;
}

runtime->pre_initialized = 1;
runtime->preinitializing = 0;
runtime->preinitialized = 1;
return _PyStatus_OK();
}

Expand Down Expand Up @@ -783,7 +788,7 @@ _Py_PreInitializeFromConfig(const PyConfig *config,
}
_PyRuntimeState *runtime = &_PyRuntime;

if (runtime->pre_initialized) {
if (runtime->preinitialized) {
/* Already initialized: do nothing */
return _PyStatus_OK();
}
Expand Down