Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,29 @@ async def run():
self.loop.run_until_complete(run())
self.assertEqual(DONE, 10)

def test_async_gen_asyncio_aclose_12(self):
DONE = 0

async def gen():
nonlocal DONE
await asyncio.sleep(1)
yield
DONE += 2

async def run():
nonlocal DONE
ag = gen()
asend_coro = ag.asend(None)
self.assertFalse(ag.ag_running)
fut = asend_coro.send(None)
self.assertTrue(ag.ag_running)
with self.assertRaises(ValueError):
await ag.asend(None)
DONE += 10

self.loop.run_until_complete(run())
self.assertEqual(DONE, 10)

def test_async_gen_asyncio_asend_01(self):
DONE = 0

Expand Down
5 changes: 5 additions & 0 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,9 +1534,11 @@ async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg)

result = gen_send_ex((PyGenObject*)o->ags_gen, arg, 0, 0);
result = async_gen_unwrap_value(o->ags_gen, result);
((PyGenObject*)o->ags_gen)->gi_running = 1;

if (result == NULL) {
o->ags_state = AWAITABLE_STATE_CLOSED;
((PyGenObject*)o->ags_gen)->gi_running = 0;
}

return result;
Expand All @@ -1562,9 +1564,11 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *args)

result = gen_throw((PyGenObject*)o->ags_gen, args);
result = async_gen_unwrap_value(o->ags_gen, result);
((PyGenObject*)o->ags_gen)->gi_running = 1;

if (result == NULL) {
o->ags_state = AWAITABLE_STATE_CLOSED;
((PyGenObject*)o->ags_gen)->gi_running = 0;
}

return result;
Expand All @@ -1575,6 +1579,7 @@ static PyObject *
async_gen_asend_close(PyAsyncGenASend *o, PyObject *args)
{
o->ags_state = AWAITABLE_STATE_CLOSED;
((PyGenObject*)o->ags_gen)->gi_running = 0;
Py_RETURN_NONE;
}

Expand Down