[New-bugs-announce] [issue37031] signalmodule.c: reuse runtime->main_thread

STINNER Victor report at bugs.python.org
Fri May 24 04:08:57 EDT 2019


New submission from STINNER Victor <vstinner at 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 <report at bugs.python.org>
<https://bugs.python.org/issue37031>
_______________________________________


More information about the New-bugs-announce mailing list