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.

Title: Propagate Python thread name to thread state structure
Type: enhancement Stage: patch review
Components: C API Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Gabriele Tornetta, arhadthedev, vstinner
Priority: normal Keywords: patch

Created on 2022-02-05 13:07 by Gabriele Tornetta, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31142 open Gabriele Tornetta, 2022-02-05 13:18
Messages (4)
msg412569 - (view) Author: Gabriele N Tornetta (Gabriele Tornetta) * Date: 2022-02-05 13:07
For tools like Austin ( it is currently quite challenging to derive the name of a thread based on the information exposed by the PyThreadState structure and one stored in threading._active. I would like to propose propagating the thread name from the Thread object to the PyThreadState structure so that profiling information from tools like Austin could easily be enriched with the names of each sampled thread.
msg412570 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-05 13:23
bpo-15500 looks like a more generic option, debuggers should be able to retrieve thread names.

faulthandler dumps "tstate->thread_id", maybe it should also dump "tstate->native_thread_id" and/or the thread name.
msg412571 - (view) Author: Gabriele N Tornetta (Gabriele Tornetta) * Date: 2022-02-05 13:32
Thanks for mentioning that issue, it didn't come up in my search for a similar one. Indeed, with the proposals in bpo-15500 implemented, and the fact that native_thread_id is already in PyThreadState, retrieving the name should be easy and might make for a better implementation than what I'm proposing. Furthermore, doing this at the OS level would benefit an even larger set of tools. What pushed me to open this issue is the fact that this feature has been lacking for quite some time (indeed bpo-15500 dates back to 2012!), so I thought I'd propose a different approach in case it would get a quicker resolution this way.
msg412574 - (view) Author: Oleg Iarygin (arhadthedev) * Date: 2022-02-05 13:55
> bpo-15500 looks like a more generic option, debuggers should be able to retrieve thread names.

That option is not viable.

1. > Created on 2012-07-30 16:19 by bra, last changed 2022-01-19 00:32 by pitrou

2. > I don't think this should be done by default as it will break people's expectations and, perhaps worse, compatibility.

3. > It is indeed the compatibility that is the worse issue.  The problem is what people have gotten used to and may have coded their applications to expect/deal with.  I agree with you that most people would *not* find it surprising to see the name reflected in the OS, but I don't think the convenience of that is worth introducing a potential backward incompatibility.

Any chances?
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90807
2022-02-05 13:55:28arhadthedevsetnosy: + arhadthedev
messages: + msg412574
2022-02-05 13:32:15Gabriele Tornettasetmessages: + msg412571
2022-02-05 13:23:28vstinnersetnosy: + vstinner
messages: + msg412570
2022-02-05 13:18:12Gabriele Tornettasetkeywords: + patch
stage: patch review
pull_requests: + pull_request29319
2022-02-05 13:07:42Gabriele Tornettacreate