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.

Title: asyncio.ensure_future() AttributeError with “async def” coroutines
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.6, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, martin.panter, python-dev, vstinner, yselivanov
Priority: normal Keywords:

Created on 2015-06-24 08:35 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg245727 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-24 08:35
While trying to port the example at <> to use “async def”, I discovered the ensure_future() function does not like the coroutine field name changes introduced in Issue 24400:

>>> asyncio.ensure_future(slow_operation(future))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/proj/python/cpython/Lib/asyncio/", line 196, in __repr__
    info = self._repr_info()
  File "/home/proj/python/cpython/Lib/asyncio/", line 105, in _repr_info
    coro = coroutines._format_coroutine(self._coro)
  File "/home/proj/python/cpython/Lib/asyncio/", line 242, in _format_coroutine
    filename = coro.gi_code.co_filename
AttributeError: 'coroutine' object has no attribute 'gi_code'

I understand the gi_ names all changed to cr_, so I guess this code has to adjust as well.
msg245728 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-06-24 08:47
It's not the first time that a bug in found in _format_coroutine(). We need more unit tests!

Previous bug:
msg245748 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-06-24 14:55
New changeset 8f4e738cb07f by Yury Selivanov in branch '3.5':
Issue #24495, #24400: Test asyncio.Task.repr in debug mode
msg245750 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-06-24 14:57
Should be fixed now. Thanks for discovering this, Martin!

Victor, I'll make a PR on github/asyncio with some refactoring or CoroWrapper etc.  The code became too cumbersome, and has to be properly refactored.  At least we should have one wrapper class for generator based coroutines, and another one for 'async def' ones.
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68683
2015-06-24 14:57:31yselivanovsetstatus: open -> closed
resolution: fixed
messages: + msg245750

stage: needs patch -> resolved
2015-06-24 14:55:48python-devsetnosy: + python-dev
messages: + msg245748
2015-06-24 08:47:29vstinnersetmessages: + msg245728
2015-06-24 08:35:27martin.pantercreate