Skip to content

Export get_all_awaited_by API into public Python API. #134342

@corona10

Description

@corona10
Member

Currently get_all_awaited_by API is provided part of _remote_debugging module.
But the module is private currently, and there are some usecase for this API from aiomonitor.

So it would be useful if we could export it as part of the asyncio API, such as 'asyncio.get_all_awaited_by'.

Please let me know if there is concern to export this API as public. @kumaraditya303 @pablogsal

cc @achimnol

Activity

achimnol

achimnol commented on May 20, 2025

@achimnol
Contributor

aiomonitor provides TUI and GUI to continuously monitor the alive tasks and their task chains.
I'd like to use get_all_awaited_by() to enhance the performance and fidelity of the information, such as async contexts shown in the pstree command.

For now, I wish I could have a programmable, public access to get_all_awaited_by() which would be compatible within the minor release (e.g., 3.14 series).

In addition, for scalability when there are thousands of running tasks while repeating the queries by a few seconds interval, I'd like to also be able to read the task tree of a single task (or a set of tasks) for detailed views of individual tasks in aiomonitor, via exact task IDs or task name patterns.

added
type-featureA feature request or enhancement
stdlibStandard Library Python modules in the Lib/ directory
on May 20, 2025
pablogsal

pablogsal commented on May 20, 2025

@pablogsal
Member

Sadly I think that for 3.14 I don't think we are ready to make these APIs public because we haven't prepare them for public consumption of anything other than proving it works and having a simple thing that dumps the task graph.

Making these APIs public now will corner us too quickly and may prevent optimising them or creating a better format.

corona10

corona10 commented on May 20, 2025

@corona10
MemberAuthor

Well, I am not saying about 3.14, maybe we can add it for 3.15. But we should define the specification of API and what attributes are actually needed, because without those API, they should hack too many things of internal CPython implementation.
Currently, they can use asyncio.tools._get_awaited_by_tasks, but it does not look safe in the future or minor release.

achimnol

achimnol commented on May 20, 2025

@achimnol
Contributor

Yes, I know 3.14 is already feature-frozen and the current private API is unstable. It will be a good starting point to experiment with, and in 3.15 we could introduce a more stable API.

pablogsal

pablogsal commented on May 20, 2025

@pablogsal
Member

My recommendation would be to play with the private version in 3.14 even if it can change and then help us design a better interface they can be performant for general use cases so we can expose it in 3.15.

This should not only include requirements but also architecture and performance considerations

achimnol

achimnol commented on May 21, 2025

@achimnol
Contributor
achimnol

achimnol commented on May 30, 2025

@achimnol
Contributor

My initial impressions:

  • The returned tuple fields should be named explicitly (e.g., using dataclasses or named tuples) to make them backward-compatible when the schema changes in the future.
  • It would be nice to have a subscription interface to "stream" the newly created tasks and terminated tasks, which should make less overheads when there are thousands of concurrent tasks.
    • I'm not sure how this could be implemented in the current "remote memory read" mechanism.
kumaraditya303

kumaraditya303 commented on Jun 6, 2025

@kumaraditya303
Contributor

I would like to keep the API private for now as it relies heavily on the internal implementation detail of per thread tasks lists which I added in 3.14. It is fine to rely on private API for experimenting as it is unlikely it would change in 3.14 now but can change in 3.15.

changed the title [-]Export append_awaited_by API into public Python API.[/-] [+]Export `get_all_awaited_by` API into public Python API.[/+] on Jun 6, 2025
pablogsal

pablogsal commented on Jun 7, 2025

@pablogsal
Member

I would like to keep the API private for now as it relies heavily on the internal implementation detail of per thread tasks lists which I added in 3.14.

This is true but the 'public' part of it relies in kind of the same way so I don't think this matters much. If we change the internal implementation the output must be the same. I am not saying we should make it public, just highlighting that it doesn't matter much because it's an implementation detail.

achimnol

achimnol commented on Jun 8, 2025

@achimnol
Contributor

Being private is okay while the API is tentative to change, but I think it is worth to do the best effort to improve backward compatibility. Using named fields would be a good starting point.

pablogsal

pablogsal commented on Jun 9, 2025

@pablogsal
Member

Using named fields would be a good starting point.

That slow down producing the data so i don't think we will be doing it

kumaraditya303

kumaraditya303 commented on Jun 10, 2025

@kumaraditya303
Contributor

This is true but the 'public' part of it relies in kind of the same way so I don't think this matters much. If we change the internal implementation the output must be the same. I am not saying we should make it public, just highlighting that it doesn't matter much because it's an implementation detail.

The output cannot be same if the internals change or any new feature is added which will change the output. Adding compatibility guarantees to introspection APIs seems a bad idea to me as it will obstruct further improvements to asyncio internals, IMO the introspection API should be able to change in major releases like from 3.14 to 3.15 but not from 3.14.1 to 3.14.2.

pablogsal

pablogsal commented on Jun 10, 2025

@pablogsal
Member

This is true but the 'public' part of it relies in kind of the same way so I don't think this matters much. If we change the internal implementation the output must be the same. I am not saying we should make it public, just highlighting that it doesn't matter much because it's an implementation detail.

The output cannot be same if the internals change or any new feature is added which will change the output. Adding compatibility guarantees to introspection APIs seems a bad idea to me as it will obstruct further improvements to asyncio internals, IMO the introspection API should be able to change in major releases like from 3.14 to 3.15 but not from 3.14.1 to 3.14.2.

You can totally change the internals without changing the output.

But in any case introspection APIs are normally stable writhing a minor release (like the debug offsets) if they are exposing things that are very low level. Here we are exposing a list of tasks and who awaits that and that can totally be stable across releases so I don't think there is a problem here

kumaraditya303

kumaraditya303 commented on Jun 12, 2025

@kumaraditya303
Contributor

You can totally change the internals without changing the output.

We can but it adds an additional constraint of keeping the output same for external tools when changing the internals of asyncio which is already constrained by many other things so I am trying to avoid adding more constraints.

I am fine with keeping it stable within a minor version like 3.14.x but not across major releases 3.x

achimnol

achimnol commented on Oct 8, 2025

@achimnol
Contributor

@kumaraditya303 I think the new callgraph API (which seems to be inspired by my aiomonitor's task creation chain with improved visibility on taskgroups) provides a good foundation for this request.

Could we have the just same/similar API for the remote case as well?

kumaraditya303

kumaraditya303 commented on Oct 18, 2025

@kumaraditya303
Contributor

Could we have the just same/similar API for the remote case as well?

That sounds reasonable to me.

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

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancement

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @achimnol@corona10@picnixz@pablogsal@kumaraditya303

        Issue actions

          Export `get_all_awaited_by` API into public Python API. · Issue #134342 · python/cpython