This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: asyncio.Task.print_stack doesn't print the full stack
Type: behavior Stage:
Components: asyncio Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amit7itz, asvetlov, chris.jerdonek, terry.reedy, yselivanov
Priority: normal Keywords:

Created on 2019-12-16 09:51 by amit7itz, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
example.py amit7itz, 2019-12-16 09:51 An example script that re-produces the bug.
Messages (5)
msg358468 - (view) Author: Amit Itzkovitch (amit7itz) Date: 2019-12-16 09:51
Hi!
I think I found some issue in the "print_stack()" function of asyncio.Task.
When I try to print the stack of some task, I only see the first few lines of the stack. 
Attached an example file, that contains a recursive function that after 10 calls prints the stack of the task. 
You can see that the stack that it prints only shows the first call of the recursive function, although you would expect to see it 10 times.

Tested on python3.7 and 3.8 on both MacOS and CentOS, the result is the same. 

Your help will be appreciated very much! :)
msg358474 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-12-16 11:38
Technically the output is correct: a stack for async function call doesn't contain the outer async function that is used for awaiting.

Agree, it may sound confusing, but `await f()` is not the same as just `f()`.

Perhaps we can provide *alternative* API for retrieving async call stack.
msg358475 - (view) Author: Amit Itzkovitch (amit7itz) Date: 2019-12-16 11:56
In is mainly confusing because I expected this function to behave like "traceback.print_stack()", which prints the stack including all the awaits that lead to it.
msg358736 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-12-20 20:18
Amit, is there a simple doc change that would have made the result clearer? (before getting Andrew's response?)
msg358792 - (view) Author: Amit Itzkovitch (amit7itz) Date: 2019-12-22 14:59
Hi Terry,
I guess the right place to update the Task.get_stack doc: https://docs.python.org/3/library/asyncio-task.html#asyncio.Task.get_stack

I'm not sure I know the terminology enough to phrase it right, but I would add there something like:
Note that the task's stack does not include the stack of coroutines that were awaited inside the task, as it is not part of the Task itself. 

But I am sure one of you can phrase it more professionally than me :)
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83241
2020-05-19 01:04:50chris.jerdoneksetnosy: + chris.jerdonek
2019-12-22 14:59:29amit7itzsetmessages: + msg358792
2019-12-20 20:18:38terry.reedysetnosy: + terry.reedy

messages: + msg358736
versions: + Python 3.8, Python 3.9
2019-12-16 11:56:05amit7itzsetmessages: + msg358475
2019-12-16 11:38:21asvetlovsetmessages: + msg358474
2019-12-16 09:51:58amit7itzcreate