-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135371: Fix asyncio introspection output to include internal coroutine chains #135436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…acks This commit refactors the C module to provide richer debugging information by introducing structured data types and exposing internal coroutine call stacks. The improvement transforms the debugging output from showing only external task dependencies to revealing the complete execution context. The key enhancement is the ability to display both the internal coroutine call stack (what the task is doing internally) and the external awaiter chain (what the task is waiting for). This dual perspective makes it much easier to understand complex async execution patterns. Before this change, the debugging output only showed file paths without function names or internal call stacks. With this improvement, developers can now see the complete picture: "foo2 -> sleep" shows the task is in a sleep call within the foo2 function, while the awaiter chain shows the external dependency structure. The implementation replaces raw tuples with structured sequences: - FrameInfo: Function name, filename, and line number - CoroInfo: Call stack and associated task name - TaskInfo: Task ID, name, coroutine stack, and awaiter relationships - ThreadInfo: Thread ID and frame information - AwaitedInfo: Thread ID and list of awaited tasks This structured approach eliminates magic indices and provides better type safety and introspection capabilities.
This commit updates the asyncio debugging tools to work with the enhanced structured data from the remote debugging module. The tools now process and display both internal coroutine stacks and external awaiter chains, providing much more comprehensive debugging information. The key improvements include: 1. Enhanced table display: Now shows both "coroutine stack" and "awaiter chain" columns, clearly separating what a task is doing internally vs what it's waiting for externally. 2. Improved tree rendering: Displays complete coroutine call stacks for leaf tasks, making it easier to understand the actual execution state of suspended coroutines. 3. Better cycle detection: Optimized DFS algorithm for detecting await cycles in the task dependency graph. 4. Structured data handling: Updated to work with the new FrameInfo, CoroInfo, TaskInfo, and AwaitedInfo structured types instead of raw tuples. The enhanced output transforms debugging from showing only file paths to revealing function names and complete call stacks, making it much easier to understand complex async execution patterns and diagnose issues in production asyncio applications.
This commit updates the test suite to work with the new structured data types introduced in the remote debugging module and asyncio tools. The tests now use proper FrameInfo, CoroInfo, TaskInfo, and AwaitedInfo structures instead of raw tuples. The test updates ensure that the enhanced debugging capabilities are properly validated, including: 1. Structured data type handling in test mock data 2. Verification of coroutine stack extraction and formatting 3. Testing of both internal coroutine stacks and external awaiter chains 4. Validation of the improved table and tree output formats These changes maintain comprehensive test coverage while adapting to the more sophisticated data structures that enable better async debugging output. The tests verify that the debugging tools correctly process and display the enhanced coroutine execution information, ensuring the new features work reliably in production environments.
This commit updates the What's New documentation to showcase the improved async debugging capabilities introduced in the remote debugging module and asyncio tools. The documentation now demonstrates the enhanced output format that provides much more detailed execution information. The key documentation updates include: 1. Updated example output showing both "coroutine stack" and "awaiter chain" columns in the table format, clearly distinguishing between internal task execution state and external dependencies. 2. Enhanced tree output examples that include function names and complete file paths with line numbers, making the debugging information much more actionable for developers. 3. Addition of cycle detection error example showing how the tools handle problematic await patterns that could indicate programming issues. The updated examples demonstrate how the enhanced debugging output transforms from showing basic file paths to revealing detailed function call stacks and execution context. This improvement makes it significantly easier for developers to understand complex async execution patterns and debug issues in production asyncio applications, especially when dealing with nested coroutines and complex task hierarchies.
d1a5d17
to
ec809b5
Compare
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
… coroutine chains (pythonGH-135436) (cherry picked from commit 028309f) Co-authored-by: Pablo Galindo Salgado <[email protected]>
GH-135509 is a backport of this pull request to the 3.14 branch. |
|
|
The raspbian buildbot looks legitimate will take a look soon. |
… coroutine chains (python#135436)
get_all_awaited_by()
shows incorrect call stacks in awaited_by relationships #135371📚 Documentation preview 📚: https://cpython-previews--135436.org.readthedocs.build/