Issue 37031: signalmodule.c: reuse runtime->main_thread
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.