Skip to content

Commit 339fc63

Browse files
committed
Add test for tricky reentrancy case (bpo-32526)
It looks like we were handling this correctly already, but let's make sure it stays that way.
1 parent e303e07 commit 339fc63

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

async_generator/test_async_generator.py

+18
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ async def recurse():
167167
async for _ in agen: # pragma: no branch
168168
pass # pragma: no cover
169169

170+
# https://bugs.python.org/issue32526
171+
@pytest.mark.asyncio
172+
async def test_reentrance_forbidden_while_suspended_in_coroutine_runner():
173+
@async_generator
174+
async def f():
175+
await asyncio.sleep(1)
176+
await yield_()
177+
178+
ag = f()
179+
asend_coro = ag.asend(None)
180+
fut = asend_coro.send(None)
181+
# Now the async generator's frame is not executing, but a call to asend()
182+
# *is* executing. Make sure that in this case, ag_running is True, and we
183+
# can't start up another call to asend().
184+
assert ag.ag_running
185+
with pytest.raises(ValueError):
186+
await ag.asend(None)
187+
170188
################################################################
171189
#
172190
# asend

0 commit comments

Comments
 (0)