diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py index 7baea69a4e5..49e4d0b95b6 100644 --- a/Lib/test/test__xxsubinterpreters.py +++ b/Lib/test/test__xxsubinterpreters.py @@ -42,7 +42,10 @@ def _run_output(interp, request, shared=None): @contextlib.contextmanager def _running(interp): r, w = os.pipe() + interpreters.list_all() + done = threading.Event() def run(): + done.set() interpreters.run_string(interp, dedent(f""" # wait for "signal" with open({r}, encoding="utf-8") as rpipe: @@ -51,6 +54,8 @@ def run(): t = threading.Thread(target=run) t.start() + done.wait() + interpreters.list_all() yield diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 5b5d2c5b03e..554049be1b3 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -1090,6 +1090,7 @@ thread_run(void *boot_raw) #endif _PyThreadState_Init(tstate); PyEval_AcquireThread(tstate); + //printf("In thread_run, the current state is: %p\n", tstate); tstate->interp->num_threads++; PyObject *res = PyObject_Call(boot->func, boot->args, boot->kwargs); diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 9290255c66c..e03c5f11307 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -1958,6 +1958,9 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr, _sharedexception *exc = NULL; int result = _run_script(interp, codestr, shared, &exc); + PyThreadState *current_tstate = PyThreadState_Get(); + printf("After interp runs, the current state is: %p\n", current_tstate); + // Switch back. if (save_tstate != NULL) { PyThreadState_Swap(save_tstate); @@ -2008,7 +2011,8 @@ _global_channels(void) { static PyObject * interp_create(PyObject *self, PyObject *args, PyObject *kwds) { - + PyThreadState *current_tstate = PyThreadState_Get(); + printf("In interp_create, the current state is: %p\n", current_tstate); static char *kwlist[] = {"isolated", NULL}; int isolated = 1; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|$i:create", kwlist, @@ -2104,6 +2108,8 @@ So does an unrecognized ID."); static PyObject * interp_list_all(PyObject *self, PyObject *Py_UNUSED(ignored)) { + PyThreadState *current_tstate = PyThreadState_Get(); + printf("In interp_list_all, the current state is: %p\n", current_tstate); PyObject *ids, *id; PyInterpreterState *interp; @@ -2172,6 +2178,8 @@ Return the ID of main interpreter."); static PyObject * interp_run_string(PyObject *self, PyObject *args, PyObject *kwds) { + PyThreadState *current_tstate = PyThreadState_Get(); + printf("Before interp runs, the current state is: %p\n", current_tstate); static char *kwlist[] = {"id", "script", "shared", NULL}; PyObject *id, *code; PyObject *shared = NULL;