8000 gh-59956: Clarify Runtime State Status Expectations by ericsnowcurrently · Pull Request #101308 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-59956: Clarify Runtime State Status Expectations #101308

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b64ce9f
Factor out tstate_verify_not_active().
ericsnowcurrently Jan 19, 2023
1be0ec4
Drop the check_current param from _PyThreadState_Delete().
ericsnowcurrently Jan 19, 2023
3454bf1
Drop _PyThreadState_Delete().
ericsnowcurrently Jan 19, 2023
a929e32
Unset the "current" thread state before zapping the threads instead o…
ericsnowcurrently Jan 19, 2023
e6ddd92
Only clear the current thread if the interpreter matches.
ericsnowcurrently Jan 19, 2023
36c512f
Always "check_current" in zapthreads().
ericsnowcurrently Jan 19, 2023
d402a82
Do not pass the runtime to _PyThreadState_DeleteExcept().
ericsnowcurrently Jan 19, 2023
2ddfe71
Add some notes, TODO comments, and asserts.
ericsnowcurrently Jan 19, 2023
99de509
Mark the main interpreter as finalizing during runtime fini.
ericsnowcurrently Jan 19, 2023
b77ae5e
Add more notes and TODO comments.
ericsnowcurrently Jan 19, 2023
9ca673c
Make PyThreadState._status more granular.
ericsnowcurrently Jan 19, 2023
8a71957
Add more status fields.
ericsnowcurrently Jan 20, 2023
62d1a93
Add a TODO.
ericsnowcurrently Jan 20, 2023
90cea92
Track active status.
ericsnowcurrently Jan 19, 2023
9965813
Clarify a TODO comment.
ericsnowcurrently Jan 20, 2023
fd5048b
Associate "bound" and "active".
ericsnowcurrently Jan 20, 2023
2105cd6
_PyThreadState_Prealloc() -> _PyT 8000 hreadState_New()
ericsnowcurrently Jan 23, 2023
8b110cf
Factor out tstate_tss_*().
ericsnowcurrently Jan 24, 2023
ca98d68
current_tss_*() -> gilstate_tss_*().
ericsnowcurrently Jan 24, 2023
4f39976
Add bind_gilstate_tstate() and unbind_gilstate_tstate().
ericsnowcurrently Jan 24, 2023
6e73669
Update some TODO comments.
ericsnowcurrently Jan 24, 2023
cc3540d
Clean up _PyThreadState_Swap() a little.
ericsnowcurrently Jan 24, 2023
1ce3841
Fix the stable ABI.
ericsnowcurrently Jan 25, 2023
121d328
Fixes for multiprocessing.
ericsnowcurrently Jan 25, 2023
8666362
Move a comment.
ericsnowcurrently Jan 25, 2023
52ac2d9
Preserve errno more carefully.
ericsnowcurrently Jan 25, 2023
f7ac19a
Do not call bind_gilstate_tstate() in bind_tstate().
ericsnowcurrently Jan 25, 2023
a338248
Add an assert.
ericsnowcurrently Jan 25, 2023
5be78e9
Clean up bind_gilstate_tstate().
ericsnowcurrently Jan 25, 2023
f019bd6
Clear bound_gilstate for the old thread state.
ericsnowcurrently Jan 25, 2023
6869bfe
bound_gilstate and gilstate_tss_get() must match.
ericsnowcurrently Jan 25, 2023
f91d458
Add a blank line for clarity.
ericsnowcurrently Jan 25, 2023
9b45398
Do not call unbind_gilstate_tstate() in unbind_tstate().
ericsnowcurrently Jan 25, 2023
98a2dae
Fix comments.
ericsnowcurrently Jan 25, 2023
afde196
Fix padding.
ericsnowcurrently Jan 30, 2023
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
Prev Previous commit
Next Next commit
_PyThreadState_Prealloc() -> _PyThreadState_New()
  • Loading branch information
ericsnowcurrently committed Jan 25, 2023
commit 2105cd69f91584856f024f42f0c3559f7879e098
2 changes: 0 additions & 2 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ struct _ts {
// Alias for backward compatibility with Python 3.8
#define _PyInterpreterState_Get PyInterpreterState_Get

PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);

/* Similar to PyThreadState_Get(), but don't issue a fatal error
* if it is NULL. */
PyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void);
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {

// PyThreadState functions

PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp);
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate);
// We keep this around exclusively for stable ABI compatibility.
PyAPI_FUNC(void) _PyThreadState_Init(
Expand Down
2 changes: 1 addition & 1 deletion Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
return PyErr_NoMemory();
}
boot->interp = _PyInterpreterState_GET();
boot->tstate = _PyThreadState_Prealloc(boot->interp);
boot->tstate = _PyThreadState_New(boot->interp);
if (boot->tstate == NULL) {
PyMem_Free(boot);
if (!PyErr_Occurred()) {
Expand Down
6 changes: 4 additions & 2 deletions Python/pylifecycle.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,11 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
const _PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
init_interp_settings(interp, &config);

PyThreadState *tstate = PyThreadState_New(interp);
PyThreadState *tstate = _PyThreadState_New(interp);
if (tstate == NULL) {
return _PyStatus_ERR("can't make first thread");
}
_PyThreadState_Bind(tstate);
(void) PyThreadState_Swap(tstate);

status = init_interp_create_gil(tstate);
Expand Down Expand Up @@ -2074,12 +2075,13 @@ new_interpreter(PyThreadState **tstate_p, const _PyInterpreterConfig *config)
return _PyStatus_OK();
}

PyThreadState *tstate = PyThreadState_New(interp);
PyThreadState *tstate = _PyThreadState_New(interp);
if (tstate == NULL) {
PyInterpreterState_Delete(interp);
*tstate_p = NULL;
return _PyStatus_OK();
}
_PyThreadState_Bind(tstate);

PyThreadState *save_tstate = PyThreadState_Swap(tstate);

Expand Down
5 changes: 3 additions & 2 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ PyThreadState_New(PyInterpreterState *interp)

// This must be followed by a call to _PyThreadState_Bind();
PyThreadState *
_PyThreadState_Prealloc(PyInterpreterState *interp)
_PyThreadState_New(PyInterpreterState *interp)
{
return new_threadstate(interp);
}
Expand Down Expand Up @@ -2066,10 +2066,11 @@ PyGILState_Ensure(void)
int has_gil;
if (tcur == NULL) {
/* Create a new Python thread state for this thread */
tcur = PyThreadState_New(runtime->gilstate.autoInterpreterState);
tcur = new_threadstate(runtime->gilstate.autoInterpreterState);
if (tcur == NULL) {
Py_FatalError("Couldn't create thread-state for new thread");
}
bind_tstate(tcur);

/* This is our thread state! We'll need to delete it in the
matching call to PyGILState_Release(). */
Expand Down
0