[New-bugs-announce] [issue37416] If threading is not imported from the main thread it sees the wrong thread as the main thread.

Fabio Zadrozny report at bugs.python.org
Wed Jun 26 14:04:42 EDT 2019


New submission from Fabio Zadrozny <fabioz at users.sourceforge.net>:

I'm attaching a snippet which shows the issue (i.e.: threading.main_thread() and threading.current_thread() should be the same and they aren't).

What I'd see as a possible solution is that the initial thread ident would be stored when the interpreter is initialized and then when threading is imported the first time it would get that indent to initialize the main thread instead of calling `threading._MainThread._set_ident` in the wrong thread.

I'm not sure if this is possible if CPython is embedded in some other C++ program, but it seems to be the correct approach when Python is called from the command line.

As a note, I found this when doing an attach to pid for the `pydevd` debugger where a thread is created to initialize the debugger (the issue on the debugger is reported at: https://github.com/microsoft/ptvsd/issues/1542).

----------
components: Interpreter Core
files: snippet.py
messages: 346653
nosy: fabioz
priority: normal
severity: normal
status: open
title: If threading is not imported from the main thread it sees the wrong thread as the main thread.
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48438/snippet.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37416>
_______________________________________


More information about the New-bugs-announce mailing list