New submission from STINNER Victor <vstin...@redhat.com>:
Currently, signalmodule.c tracks the "main thread" and the "main interpreter": main_thread = PyThread_get_thread_ident(); main_interp = _PyInterpreterState_Get(); This information is already tracked in the global _PyRuntime variable which is updated at fork by _PyRuntimeState_ReInitThreads() (called by PyOS_AfterFork_Child). Attached PR removes main_thread and main_interp from signalmodule.c, to reuse _PyRuntime. It should help to ensure that Python remains consistent (less risk of inconsistency if one variable is updated, but not the other). By the way, _PyInterpreterState_DeleteExceptMain() is called before _PyRuntimeState_ReInitThreads(). _PyInterpreterState_DeleteExceptMain() acquires runtime->interpreters.mutex, whereas this lock is reset by _PyRuntimeState_ReInitThreads(). Maybe I introduced this bug recently when I refactored code, I don't know. But it sounds like a bug as well. Note: PyOS_AfterFork_Child() doesn't update runtime->interpreters->main, but os.fork() raises a RuntimeError if it's not called from the main interpreter. So it's fine. ---------- components: Interpreter Core messages: 343350 nosy: vstinner priority: normal severity: normal status: open title: signalmodule.c: reuse runtime->main_thread versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37031> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com