New submission from Fabio Zadrozny <fab...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue37416>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to