Make asyncio debug offsets reachable from _PyRuntime and give them a cookie, version and size #160107
Copy link
Copy link
Open
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
I work on Datadog's Python profiler. I used AI to help write this and have reviewed it.
Proposal
Make the asyncio debug offsets reachable from _PyRuntime, and give them a header like _Py_DebugOffsets has:
- Add
void *asyncio_debug_offsetsto_PyRuntimeStateand publish its offset in_Py_DebugOffsets.runtime_state._asynciosets it during module init; NULL means_asyncioisn't initialized yet. - Start the asyncio table with a cookie,
PY_VERSION_HEXand its size. _remote_debuggingfollows the pointer and checks the header. Keep theAsyncioDebugsection for existing tools.
This changes both table layouts, so it's 3.16-only.
Why
- Discovery.
_Py_DebugOffsetssits at the start of_PyRuntime, which is exported. Nothing points to the asyncio table and_Py_AsyncioDebugisn't exported, so readers search loaded files by name for theAsyncioDebugsection and parse ELF/Mach-O/PE headers from disk. The name filter already had to change once (_asyncio.cpythonin 3.14,pythonafter build_asynciomodule as static module #136669). - Validation. The table has no cookie, version or size.
_remote_debuggingchecks the cookie of eachPyRuntimecandidate, but takes the firstAsyncioDebugsection it finds.
How it would be used
_remote_debugging, and in-process samplers such as DataDog/dd-trace-py#19802, would read the pointer from _PyRuntime, check the header, and then read the table, with no section search.
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:
- Async Call-Stack Reconstruction #91048: added the asyncio debug offsets and the
AsyncioDebugsection - Harden validation of remote debugging offset tables #148178: validation of the remote debug offset tables
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Projects
- StatusShow more project fieldsTodo
Activity
pythongh-160107: Make AsyncioDebug reachable from _PyRuntime and add …
kumaraditya303 commentedon Oct 28, 2026
cc @pablogsal
pablogsal commentedon Oct 28, 2026
Will take a look at this this week
pablogsal commentedon Oct 28, 2026
@taegyunkim please don't open PRs until we agree on a solution. Until we agree on something the PR doesn't help as we can all prompt our agents to experiment.
pablogsal commentedon Oct 28, 2026
Also please avoid opening these super verbose AI issues there are very noisy and we need to do quite a lot of effort to cut through the ai noise
taegyunkim commentedon Oct 28, 2026
Yep, that was my mistake as noted in the PR, and thanks for closing it
I tried it to be more thorough but I'll make sure it's to the point so you can spend less time on it. And trimmed it to the point. Hope this helps.
Thanks for taking a look