This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients aldwinaldwin, brett.cannon, eric.snow, fabioz, int19h
Date 2019-06-27.15:48:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1561650521.4.0.736967472172.issue37416@roundup.psfhosted.org>
In-reply-to
Content
Note that in Python 3.7 we consolidated a bunch of the global runtime state.  The "main_thread" static in ceval.c moved to the internal struct _PyRuntimestate and in 3.7 it is accessible as _Runtime.ceval.pending.main_thread (but only if you build with Py_BUILD_CORE, which extensions shouldn't).  In 3.8 it was moved to the top of the struct as _PyRuntimeState.main_thread.  All that said, that thread ID is still not exposed directly in Python.

So perhaps it would make sense to add something like sys.get_main_thread_id, which Lib/threading.py could then use (rather than assuming the current (during import) thread is the main thread).

Unfortunately, this wouldn't help with anything earlier than 3.9.  Currently 3.8 is already in beta1, where we apply a feature freeze, so it's barely too late for 3.8.  I suppose you could ask for a special exception from the release manager, given the change would be relatively small, with real benefits, but don't expect it. :)
History
Date User Action Args
2019-06-27 15:48:41eric.snowsetrecipients: + eric.snow, brett.cannon, fabioz, aldwinaldwin, int19h
2019-06-27 15:48:41eric.snowsetmessageid: <1561650521.4.0.736967472172.issue37416@roundup.psfhosted.org>
2019-06-27 15:48:41eric.snowlinkissue37416 messages
2019-06-27 15:48:41eric.snowcreate