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

asynccontextmanager fails in 3.7-dev #30

Open
mhchia opened this issue Feb 3, 2020 · 1 comment
Open

asynccontextmanager fails in 3.7-dev #30

mhchia opened this issue Feb 3, 2020 · 1 comment

Comments

@mhchia
Copy link

mhchia commented Feb 3, 2020

Python version: Python 3.7.6+ (heads/3.7:b0a6ec256b)
OS: macOS 10.14.6

async_generator.asynccontextmanager started to fail in python 3.7-dev(which is also the 3.7-dev in pyenv).
If we change to use contextlib.asynccontextmanager, it works. It's why I'm thinking something wrong in async_generator when an async-generator is being closed. I'm sorry that I haven't dug into the cause.

This issue seems to happen since python/cpython@b76d5e9.

# example_code.py

import asyncio

from async_generator import asynccontextmanager


@asynccontextmanager
async def async_iterator():
    yield 1


async def run():
    async with async_iterator():
        ...


asyncio.run(run())
# Output of the executed code

an error occurred during closing of asynchronous generator <async_generator object async_iterator at 0x108632290>
asyncgen: <async_generator object async_iterator at 0x108632290>
Traceback (most recent call last):
  File "/Users/mhchia/.pyenv/versions/3.7-dev/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/Users/mhchia/.pyenv/versions/3.7-dev/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
    return future.result()
  File "/Users/mhchia/projects/practice/python/async-generator/await-twice.py", line 13, in run
    ...
  File "/Users/mhchia/.pyenv/versions/3.7-dev/envs/py-libp2p-3.7-dev/lib/python3.7/site-packages/async_generator/_util.py", line 84, in __aexit__
    raise
  File "/Users/mhchia/.pyenv/versions/3.7-dev/envs/py-libp2p-3.7-dev/lib/python3.7/site-packages/async_generator/_util.py", line 14, in __aexit__
    await self._aiter.aclose()
RuntimeError: cannot reuse already awaited aclose()/athrow()

During handling of the above exception, another exception occurred:

RuntimeError: cannot reuse already awaited aclose()/athrow()
Traceback (most recent call last):
  File "/Users/mhchia/projects/practice/python/async-generator/await-twice.py", line 16, in <module>
    asyncio.run(run())
  File "/Users/mhchia/.pyenv/versions/3.7-dev/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/Users/mhchia/.pyenv/versions/3.7-dev/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
    return future.result()
  File "/Users/mhchia/projects/practice/python/async-generator/await-twice.py", line 13, in run
    ...
  File "/Users/mhchia/.pyenv/versions/3.7-dev/envs/py-libp2p-3.7-dev/lib/python3.7/site-packages/async_generator/_util.py", line 84, in __aexit__
    raise
  File "/Users/mhchia/.pyenv/versions/3.7-dev/envs/py-libp2p-3.7-dev/lib/python3.7/site-packages/async_generator/_util.py", line 14, in __aexit__
    await self._aiter.aclose()
RuntimeError: cannot reuse already awaited aclose()/athrow()
@njsmith
Copy link
Member

njsmith commented Feb 3, 2020

Huh, weird. @oremanj, this seems like the kind of weird issue you enjoy digging into, any chance you want to take a look? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants