python / python/cpython

Keep Track of Where Each Python Thread Was Started

Open
#125,928 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

Debugging threads can be tricky. One thing that could sometimes help would be knowing where Thread.start() was called. We could achieve this by capturing the traceback of the call and attaching it to the thread. We probably wouldn't want to keep the actual traceback, due to how that would leak all the frames, etc. Instead, we'd probably want to use traceback.TracebackSummary or perhaps even something more lightweight. (FYI, there are other places where such a lightweight traceback snapshot would be useful.)

FWIW, the same sort of tracking might be helpful for coroutines (asyncio), though this is partly addressed by https://github.com/python/cpython/pull/124640.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Thread.start() entry point and traceback.TracebackSummary to understand the proposed capture and storage boundaries. Define the design with the threading maintainers, then add coverage showing that a thread records where it was started without retaining live traceback frames.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.