-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Description
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
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Todo
Milestone
Relationships
Development
Select code repository
Activity
achimnol commentedon May 20, 2025
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 thepstreecommand.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.
pablogsal commentedon May 20, 2025
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 commentedon May 20, 2025
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 commentedon May 20, 2025
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 commentedon May 20, 2025
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 commentedon May 21, 2025
FYI, I'm testing the current private API here:
https://discuss.python.org/t/testing-asyncio-tools-get-all-awaited-by/92805
achimnol commentedon May 30, 2025
My initial impressions:
kumaraditya303 commentedon Jun 6, 2025
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.
[-]Export append_awaited_by API into public Python API.[/-][+]Export `get_all_awaited_by` API into public Python API.[/+]pablogsal commentedon Jun 7, 2025
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 commentedon Jun 8, 2025
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 commentedon Jun 9, 2025
That slow down producing the data so i don't think we will be doing it
kumaraditya303 commentedon Jun 10, 2025
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 commentedon Jun 10, 2025
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 commentedon Jun 12, 2025
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
asyncio ps#134861achimnol commentedon Oct 8, 2025
@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 commentedon Oct 18, 2025
That sounds reasonable to me.