Skip to content

_PyEval_SetTrace is no longer available in C API since 3.13 #127748

@dalazx

Description

@dalazx

Bug report

Bug description:

Hello,

Prior 3.13 it was possible to set a trace in a specific thread from another thread by leveraging _PyEval_SetTrace, with pure Python. Now one can either set a trace for the current thread or all the threads using PyEval_SetTrace or PyEval_SetTraceAllThreads.
The change:
https://github.com/python/cpython/pull/108433/files#diff-9e7eb7e81667528dfa3a35bbf32fe622d4721c3c71385ea0ea2250abbd15d545R21
Interestingly, the profiling counterpart seems to be still available in the C API.

The use case I am interested in is a dedicated monitoring thread connected to a distributed observability system. This thread itself should not be traced as it manages tracing for the rest of the process.

Would it be possible to reinstate _PyEval_SetTrace back to the private C API?

Also, the new sys.monitoring module seems to offer a more high-level interface for debuggers and profilers, but it is unclear whether it is possible to limit the events to a certain thread. (unless of course one checks every event which does not seem efficient).

Alternatively, would writing an extension to expose this function be a better approach?

I would greatly appreciate any comments or suggestions regarding this. Thank you!

cc @vstinner

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixestopic-C-APItype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions