Skip to content
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

asyncio.ensure_future() AttributeError with “async def” coroutines #68683

Closed
vadmium opened this issue Jun 24, 2015 · 4 comments
Closed

asyncio.ensure_future() AttributeError with “async def” coroutines #68683

vadmium opened this issue Jun 24, 2015 · 4 comments
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Jun 24, 2015

BPO 24495
Nosy @gvanrossum, @vstinner, @vadmium, @1st1

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-06-24.14:57:31.243>
created_at = <Date 2015-06-24.08:35:27.899>
labels = ['type-bug', 'expert-asyncio']
title = 'asyncio.ensure_future() AttributeError with \xe2\x80\x9casync def\xe2\x80\x9d coroutines'
updated_at = <Date 2015-06-24.14:57:31.242>
user = 'https://github.com/vadmium'

bugs.python.org fields:

activity = <Date 2015-06-24.14:57:31.242>
actor = 'yselivanov'
assignee = 'none'
closed = True
closed_date = <Date 2015-06-24.14:57:31.243>
closer = 'yselivanov'
components = ['asyncio']
creation = <Date 2015-06-24.08:35:27.899>
creator = 'martin.panter'
dependencies = []
files = []
hgrepos = []
issue_num = 24495
keywords = []
message_count = 4.0
messages = ['245727', '245728', '245748', '245750']
nosy_count = 5.0
nosy_names = ['gvanrossum', 'vstinner', 'python-dev', 'martin.panter', 'yselivanov']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue24495'
versions = ['Python 3.5', 'Python 3.6']

@vadmium
Copy link
Member Author

vadmium commented Jun 24, 2015

While trying to port the example at <https://docs.python.org/3.5/library/asyncio-task.html#example-future-with-run-until-complete\> to use “async def”, I discovered the ensure_future() function does not like the coroutine field name changes introduced in bpo-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/futures.py", line 196, in __repr__
    info = self._repr_info()
  File "/home/proj/python/cpython/Lib/asyncio/tasks.py", line 105, in _repr_info
    coro = coroutines._format_coroutine(self._coro)
  File "/home/proj/python/cpython/Lib/asyncio/coroutines.py", 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.

@vadmium vadmium added topic-asyncio type-bug An unexpected behavior, bug, or error labels Jun 24, 2015
@vstinner
Copy link
Member

It's not the first time that a bug in found in _format_coroutine(). We need more unit tests!

Previous bug: python/asyncio#222

@python-dev
Copy link
Mannequin

python-dev mannequin commented Jun 24, 2015

New changeset 8f4e738cb07f by Yury Selivanov in branch '3.5':
Issue bpo-24495, bpo-24400: Test asyncio.Task.repr in debug mode
https://hg.python.org/cpython/rev/8f4e738cb07f

@1st1
Copy link
Member

1st1 commented Jun 24, 2015

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.

@1st1 1st1 closed this as completed Jun 24, 2015
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants