Skip to content

Faulthandler output should include the thread name #125434

Closed

Description

@spacemanspiff2007

Feature or enhancement

Proposal:

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

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. rruuaanng commented on Oct 15, 2024

    @rruuaanng
    Contributor

    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).

  2. spacemanspiff2007 commented on Oct 15, 2024

    @spacemanspiff2007
    ContributorAuthor

    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.

  3. vstinner commented on Nov 27, 2024

    @vstinner
    Member

    I don't think that we can implement this feature.

    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).

    I suggest to close this issue as "won't fix".

  4. picnixz commented on Nov 27, 2024

    @picnixz
    Member

    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.

  5. added
    pendingThe issue will be closed if no feedback is provided
    on Nov 27, 2024
  6. vstinner commented on Nov 27, 2024

    @vstinner
    Member

    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.

  7. vstinner commented on Nov 29, 2024

    @vstinner
    Member

    I wrote a change to set the thread name to the operating system: #127338

  8. removed
    pendingThe issue will be closed if no feedback is provided
    on Nov 29, 2024
  9. added a commit that references this issue on Apr 2, 2025
  10. vstinner commented on Apr 2, 2025

    @vstinner
    Member

    I wrote PR gh-132016 to display the thread native name in faulthandler.

  11. added a commit that references this issue on Apr 4, 2025
  12. added 2 commits that reference this issue on Apr 11, 2025
  13. 7 remaining items

  14. added a commit that references this issue on Oct 27, 2025
  15. vstinner commented on Oct 27, 2025

    @vstinner
    Member

    The feature is now supported on Windows as well.

  16. sergey-miryanov commented on Oct 27, 2025

    @sergey-miryanov
    Contributor

    Thanks!

  17. added 4 commits that reference this issue on Oct 28, 2025
  18. vstinner commented on Oct 28, 2025

    @vstinner
    Member

    I merged a second fix for Windows to display correctly non-ASCII thread names.

  19. added 3 commits that reference this issue on Nov 27, 2025
  20. added 2 commits that reference this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions