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: PyAsyncGenObject causes task.get_stack() raising AttributeError
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, lidiz, miss-islington, yselivanov
Priority: normal Keywords: patch

Created on 2020-02-26 19:25 by lidiz, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18669 merged lidiz, 2020-02-26 19:25
PR 18742 merged miss-islington, 2020-03-02 12:46
Messages (3)
msg362722 - (view) Author: Lidi Zheng (lidiz) * Date: 2020-02-26 19:25
This issue exists since 3.6.

The implementation of get stack on Task is looking for two attribute [1]: "cr_frame" for coroutines, "gi_frame" for generators (legacy coroutines). However, PyAsyncGenObject provides none of them but "ag_frame" [2].

Fix PR: https://github.com/python/cpython/pull/18669

A simple reproduce:

    def test_async_gen_aclose_compatible_with_get_stack(self):
        async def async_generator():
            yield object()

        async def run():
            ag = async_generator()
            asyncio.create_task(ag.aclose())
            tasks = asyncio.all_tasks()
            for task in tasks:
                # No AttributeError raised
                task.get_stack()

        self.loop.run_until_complete


I found this in my project I want to view who created the Tasks.

[1] https://github.com/python/cpython/blob/21da76d1f1b527d62b2e9ef79dd9aa514d996341/Lib/asyncio/base_tasks.py#L27
[2] https://github.com/python/cpython/blob/21da76d1f1b527d62b2e9ef79dd9aa514d996341/Objects/genobject.c#L1329
msg363168 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2020-03-02 12:46
New changeset 4482337decdbd0c6e2150346a68b3616bda664aa by Lidi Zheng in branch 'master':
bpo-39764: Make Task.get_stack accept ag_frame (#18669)
https://github.com/python/cpython/commit/4482337decdbd0c6e2150346a68b3616bda664aa
msg363170 - (view) Author: miss-islington (miss-islington) Date: 2020-03-02 13:04
New changeset 43932dc1eaf36d75b2ee0420d8be747001315c26 by Miss Islington (bot) in branch '3.8':
bpo-39764: Make Task.get_stack accept ag_frame (GH-18669)
https://github.com/python/cpython/commit/43932dc1eaf36d75b2ee0420d8be747001315c26
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 83945
2020-03-02 13:06:37asvetlovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-03-02 13:04:07miss-islingtonsetmessages: + msg363170
2020-03-02 12:46:07miss-islingtonsetkeywords: + patch
nosy: + miss-islington

pull_requests: + pull_request18097
stage: patch review
2020-03-02 12:46:05asvetlovsetmessages: + msg363168
2020-02-26 19:25:53lidizcreate