Author njs
Recipients achimnol, asvetlov, njs, yselivanov
Date 2018-01-10.22:05:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1515621909.73.0.467229070634.issue32526@psf.upfronthosting.co.za>
In-reply-to
Content
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):

>>> async def f():
...     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: https://github.com/njsmith/async_generator/commit/339fc6309aa6c96244e79b517db0b98ba0ccfb2a
History
Date User Action Args
2018-01-10 22:05:09njssetrecipients: + njs, asvetlov, yselivanov, achimnol
2018-01-10 22:05:09njssetmessageid: <1515621909.73.0.467229070634.issue32526@psf.upfronthosting.co.za>
2018-01-10 22:05:09njslinkissue32526 messages
2018-01-10 22:05:09njscreate