GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||
GeezerVison is showing github.com — gh-104690: thread_run() checks for tstate dangling pointer by vstinner · Pull Request #109056 · python/cpython Conversation
|
|
This change provides a better error message rather than a blind crash. It should help debugging complicated crashes. Example: Patch to reintroduce the bug: diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 49f34fcb9f..f5fc209e88 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -1158,11 +1161,13 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) "thread is not supported for isolated subinterpreters"); return NULL; } +#if 0 if (interp->finalizing) { PyErr_SetString(PyExc_RuntimeError, "can't create new thread at interpreter shutdown"); return NULL; } +#endif struct bootstate *boot = PyMem_NEW(struct bootstate, 1); if (boot == NULL) { Script import atexit import threading def t0(): pass def t1(): threading.Thread(target=t0).start() def f(): threading.Thread(target=t1).start() atexit.register(f) exit() |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't think that it's related, but in a recent job on Windows x86, the following assertion failed while running test_threading() in a test worker process: Related code: static void bind_tstate(PyThreadState *tstate) { assert(tstate != NULL); assert(tstate_is_alive(tstate) && !tstate->_status.bound); /// <=== HERE, line 245 assert(!tstate->_status.unbound); // just in case assert(!tstate->_status.bound_gilstate); assert(tstate != gilstate_tss_get(tstate->interp->runtime)); assert(!tstate->_status.active); assert(tstate->thread_id == 0); assert(tstate->native_thread_id == 0); I don't know if it would be worth it to repeat the See: #108987 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oh! I managed to reproduce issue #108987 on Windows 32-bit with my PR and I get: So apparently, thread_run() is called after PyInterpreterState_Delete() has been called! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @vstinner, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @vstinner, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…hon#109056) thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c. (cherry picked from commit f63d378)
|
GH-109133 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-109134 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…hon#109056) thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c. (cherry picked from commit f63d378)
…09056) (#109134) gh-104690: thread_run() checks for tstate dangling pointer (#109056) thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c. (cherry picked from commit f63d378)
…09056) (#109133) gh-104690: thread_run() checks for tstate dangling pointer (#109056) thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c. (cherry picked from commit f63d378)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.