You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=Noneclosed_at=<Date2019-10-22.22:24:16.987>created_at=<Date2018-01-10.09:31:53.662>labels= ['type-bug', '3.7', 'expert-asyncio']
title='Closing async generator while it is running does not raise an exception'updated_at=<Date2019-10-22.22:24:16.986>user='https://github.com/achimnol'
Just run this code using "python -m pytest -s test.py" to see what happens.
(My setup uses Python 3.6.4 and pytest 3.3.2 on macOS High Sierra 10.13.2)
I tried the same logic using synchornous APIs such as threading.Thread / time.sleep instead of loop.create_task / asyncio.sleep, it raised "ValueError: generator already executing" when tried to close the generator.
It looks like Python's tracking the "running" state of async generators wrong: we should have ag_running set to True when we enter asend/athrow/aclose and False when we exit, but instead it's being toggled back and forth on each *inner* send/throw on the individual coroutines.
Here's a minimal reproducer (using some random recent checkout of master):
>>> asyncdeff():
... await asyncio.sleep(1)
... yield
...
>>> ag = f()
>>> asend_coro = ag.asend(None)
>>> fut = asend_coro.send(None)
# Logically, ag.asend is still running, waiting for that sleep to
# finish, but we have lost track:
>>> ag.ag_running
False
# We can start another call to asend() going simultaneously
>>> fut.set_result(None)
>>> send_coro2 = ag.asend(None)
>>> send_coro2.send(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
It looks like async_generator did handle this case correctly, but didn't have a test case. I just added one: njsmith/async_generator@339fc63
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: