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.
# 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()
Python version:
Python 3.7.6+ (heads/3.7:b0a6ec256b)
OS:macOS 10.14.6
async_generator.asynccontextmanager
started to fail in python3.7-dev
(which is also the3.7-dev
inpyenv
). If we change to usecontextlib.asynccontextmanager
, it works. It's why I'm thinking something wrong inasync_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 https://github.com/python/cpython/commit/b76d5e9ee64b8ac861e856d8e41289c0977c75e1.