8000 Add test · Python-Repository-Hub/cpython@26a0f10 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26a0f10

Browse files
committed
Add test
1 parent d1ea1d3 commit 26a0f10

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Lib/test/test_asyncio/test_tasks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,25 @@ async def run():
496496
# This also distinguishes from the initial has_cycle=None.
497497
self.assertEqual(has_cycle, False)
498498

499+
def test___cancel_requested__(self):
500+
loop = asyncio.new_event_loop()
501+
502+
async def task():
503+
await asyncio.sleep(10)
504+
return 12
505+
506+
try:
507+
t = self.new_task(loop, task())
508+
self.assertFalse(t.__cancel_requested__)
509+
self.assertTrue(t.cancel())
510+
self.assertTrue(t.__cancel_requested__)
511+
self.assertFalse(t.cancel())
512+
513+
with self.assertRaises(asyncio.CancelledError):
514+
loop.run_until_complete(t)
515+
finally:
516+
loop.close()
517+
499518
def test_cancel(self):
500519

501520
def gen():

Modules/_asynciomodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,8 +2506,8 @@ static PyGetSetDef TaskType_getsetlist[] = {
25062506
{"_must_cancel", (getter)TaskObj_get_must_cancel, NULL, NULL},
25072507
{"_coro", (getter)TaskObj_get_coro, NULL, NULL},
25082508
{"_fut_waiter", (getter)TaskObj_get_fut_waiter, NULL, NULL},
2509-
{"__task_cancel_requested__", (getter)TaskObj_get_cancel_requested,
2510-
(setter)TaskObj_set_cancel_requested, NULL},
2509+
{"__cancel_requested__", (getter)TaskObj_get_cancel_requested,
2510+
(setter)TaskObj_set_cancel_requested, NULL},
25112511
{NULL} /* Sentinel */
25122512
};
25132513

0 commit comments

Comments
 (0)
0