Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add test
  • Loading branch information
asvetlov committed Feb 13, 2022
commit 26a0f1056a738c2ec7a9ed8f06239c3d9894d30d
19 changes: 19 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,25 @@ async def run():
# This also distinguishes from the initial has_cycle=None.
self.assertEqual(has_cycle, False)

def test___cancel_requested__(self):
loop = asyncio.new_event_loop()

async def task():
await asyncio.sleep(10)
return 12

try:
t = self.new_task(loop, task())
self.assertFalse(t.__cancel_requested__)
self.assertTrue(t.cancel())
self.assertTrue(t.__cancel_requested__)
self.assertFalse(t.cancel())

with self.assertRaises(asyncio.CancelledError):
loop.run_until_complete(t)
finally:
loop.close()

def test_cancel(self):

def gen():
Expand Down
4 changes: 2 additions & 2 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2506,8 +2506,8 @@ static PyGetSetDef TaskType_getsetlist[] = {
{"_must_cancel", (getter)TaskObj_get_must_cancel, NULL, NULL},
{"_coro", (getter)TaskObj_get_coro, NULL, NULL},
{"_fut_waiter", (getter)TaskObj_get_fut_waiter, NULL, NULL},
{"__task_cancel_requested__", (getter)TaskObj_get_cancel_requested,
(setter)TaskObj_set_cancel_requested, NULL},
{"__cancel_requested__", (getter)TaskObj_get_cancel_requested,
(setter)TaskObj_set_cancel_requested, NULL},
{NULL} /* Sentinel */
};

Expand Down