You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Faulthandler output should include the thread name #125434
Currently faulthandler just dumps the thread id.
It would be nice if the thread name would also be part of the output since this makes debugging much easier
Current output
Thread 0x00003b9c (most recent call first):
File "C:\ProgramFiles\Python\Python312\Lib\concurrent\futures\thread.py", line 89 in _worker
File "C:\ProgramFiles\Python\Python312\Lib\threading.py", line 1012 in run
File "C:\ProgramFiles\Python\Python312\Lib\threading.py", line 1075 in _bootstrap_inner
File "C:\ProgramFiles\Python\Python312\Lib\threading.py", line 1032 in _bootstrap
...
Better output with thread name in square brackets
Thread 0x00003b9c [Thread pool worker 1] (most recent call first):
File "C:\ProgramFiles\Python\Python312\Lib\concurrent\futures\thread.py", line 89 in _worker
File "C:\ProgramFiles\Python\Python312\Lib\threading.py", line 1012 in run
File "C:\ProgramFiles\Python\Python312\Lib\threading.py", line 1075 in _bootstrap_inner
File "C:\ProgramFiles\Python\Python312\Lib\threading.py", line 1032 in _bootstrap
...
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Sorry, It seems that there is no thread name member in PyThreadState :(. In my opinion, The thread name does not make much sense, although it is more convenient for debugging.
(Maybe I didn't find it).
If it's not there it obviously can't be included. Thank you very much for looking!
I'm debugging an asyncio applications which also uses a thread pool.
Since I'm only interested in the threads from the thread pool the thread name would have been a very easy and convenient way to identify these threads.
Sadly, faulthandler is very low-level. It doesn't have access to threading.Threading.name attribute. It cannot import a module or do complex operation.
faulthandler is called in a signal handler, only "async signal-safe" function can be used, memory can only be allocated on the stack (not on the heap).
One approach would be to set the thread name in the OS: #59705 and then retrieve the thread name from the OS. It might work if retrieving the name is safe in a signal handler.
Activity
rruuaanng commentedon Oct 15, 2024
Sorry, It seems that there is no thread name member in
PyThreadState:(. In my opinion, The thread name does not make much sense, although it is more convenient for debugging.(Maybe I didn't find it).
spacemanspiff2007 commentedon Oct 15, 2024
If it's not there it obviously can't be included. Thank you very much for looking!
I'm debugging an asyncio applications which also uses a thread pool.
Since I'm only interested in the threads from the thread pool the thread name would have been a very easy and convenient way to identify these threads.
vstinner commentedon Nov 27, 2024
I don't think that we can implement this feature.
Sadly, faulthandler is very low-level. It doesn't have access to
threading.Threading.nameattribute. It cannot import a module or do complex operation.faulthandler is called in a signal handler, only "async signal-safe" function can be used, memory can only be allocated on the stack (not on the heap).
I suggest to close this issue as "won't fix".
picnixz commentedon Nov 27, 2024
I think I'll follow Victor's call. I had a quick look at the code to see how we could make it include the thread name but I don't think it's feasible.
One possibility is to carry the latter everywhere but since only stack-allocated memory can be used I really don't think we can have a simple fix.
vstinner commentedon Nov 27, 2024
One approach would be to set the thread name in the OS: #59705 and then retrieve the thread name from the OS. It might work if retrieving the name is safe in a signal handler.
vstinner commentedon Nov 29, 2024
I wrote a change to set the thread name to the operating system: #127338
pythongh-125434: Display thread name in faulthandler
vstinner commentedon Apr 2, 2025
I wrote PR gh-132016 to display the thread native name in faulthandler.
gh-125434: Display thread name in faulthandler (#132016)
pythongh-125434: Fix building on OpenBSD
gh-125434: Fix building on OpenBSD (GH-132393)
7 remaining items
gh-125434: Display thread name in faulthandler on Windows (#140675)
vstinner commentedon Oct 27, 2025
The feature is now supported on Windows as well.
sergey-miryanov commentedon Oct 27, 2025
Thanks!
pythongh-125434: Fix non-ASCII thread names in faulthandler on Windows
pythongh-125434: Fix non-ASCII thread names in faulthandler on Windows
pythongh-125434: Fix non-ASCII thread names in faulthandler on Windows
gh-125434: Fix non-ASCII thread names in faulthandler on Windows (#14…
vstinner commentedon Oct 28, 2025
I merged a second fix for Windows to display correctly non-ASCII thread names.
pythongh-125434: Display thread name in faulthandler on Windows (pyth…
pythongh-125434: Fix non-ASCII thread names in faulthandler on Windows (
[3.14] gh-125434: Display thread name in faulthandler on Windows (#14…
pythongh-125434: Display thread name in faulthandler on Windows (pyth…
pythongh-125434: Fix non-ASCII thread names in faulthandler on Windows (