[New-bugs-announce] [issue39042] Use the runtime's main thread ID in the threading module.

Eric Snow report at bugs.python.org
Fri Dec 13 17:21:22 EST 2019

New submission from Eric Snow <ericsnowcurrently at gmail.com>:

The threading module has a "main_thread()" function that returns a Thread instance for the "main" thread.  The main thread is the one running when the runtime is initialized and has a specific role in various parts of the runtime.  Currently the threading module instead uses the ID of the thread where the module is imported for the first time.  Usually this isn't a problem. (perhaps only in embedding cases?)

Since 3.8 we store the ID of the thread where the runtime was initialized (_PyRuntime.main_thread).  By using this in the threading module we can be consistent across the runtime about what the main thread is.

This is particularly significant because in 3.8 we also updated the signal module to use _PyRuntime.main_thread (instead of calling PyThread_get_thread_ident() when the module is loaded).  See issue38904.

We should also consider backporting this change to 3.8, to resolve the difference between the threading and signal modules.

components: Library (Lib)
messages: 358362
nosy: eric.snow
priority: normal
severity: normal
stage: test needed
status: open
title: Use the runtime's main thread ID in the threading module.
type: behavior
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list