8000 [3.12] gh-105716: Support Background Threads in Subinterpreters Consistently (gh-109921) by ericsnowcurrently · Pull Request #110707 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.12] gh-105716: Support Background Threads in Subinterpreters Consistently (gh-109921) #110707

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move "threads.main" down, for 3.12.0 layout compatibility.
  • Loading branch information
ericsnowcurrently committed Nov 20, 2023
commit 0843fd716756540a1d6596fe99ea838cc7bc2f4c
5 changes: 3 additions & 2 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ struct _is {
uint64_t next_unique_id;
/* The linked list of threads, newest first. */
PyThreadState *head;
/* The thread currently executing in the __main__ module, if any. */
PyThreadState *main;
/* Used in Modules/_threadmodule.c. */
long count;
/* Support for runtime thread stack size tuning.
Expand Down Expand Up @@ -196,6 +194,9 @@ struct _is {
struct _Py_interp_cached_objects cached_objects;
struct _Py_interp_static_objects static_objects;

/* The thread currently executing in the __main__ module, if any. */
PyThreadState *threads_main;

/* the initial PyInterpreterState.threads.head */
PyThreadState _initial_thread;
};
Expand Down
10 changes: 5 additions & 5 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime)
int
_PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
{
if (interp->threads.main != NULL) {
if (interp->threads_main != NULL) {
PyErr_SetString(PyExc_RuntimeError,
"interpreter already running");
return -1;
Expand All @@ -1060,21 +1060,21 @@ _PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
"current tstate has wrong interpreter");
return -1;
}
interp->threads.main = tstate;
interp->threads_main = tstate;
return 0;
}

void
_PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp)
{
assert(interp->threads.main == current_fast_get(&_PyRuntime));
interp->threads.main = NULL;
assert(interp->threads_main == current_fast_get(&_PyRuntime));
interp->threads_main = NULL;
}

int
_PyInterpreterState_IsRunningMain(PyInterpreterState *interp)
{
return (interp->threads.main != NULL);
return (interp->threads_main != NULL);
}


Expand Down
0