MCPcopy Index your code
hub / github.com/python/cpython / test_uncancel_basic

Method test_uncancel_basic

Lib/test/test_asyncio/test_tasks.py:542–582  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

540 loop.close()
541
542 def test_uncancel_basic(self):
543 loop = asyncio.new_event_loop()
544
545 async def task():
546 try:
547 await asyncio.sleep(10)
548 except asyncio.CancelledError:
549 self.current_task().uncancel()
550 await asyncio.sleep(10)
551
552 try:
553 t = self.new_task(loop, task())
554 loop.run_until_complete(asyncio.sleep(0.01))
555
556 # Cancel first sleep
557 self.assertTrue(t.cancel())
558 self.assertIn(" cancelling ", repr(t))
559 self.assertEqual(t.cancelling(), 1)
560 self.assertFalse(t.cancelled()) # Task is still not complete
561 loop.run_until_complete(asyncio.sleep(0.01))
562
563 # after .uncancel()
564 self.assertNotIn(" cancelling ", repr(t))
565 self.assertEqual(t.cancelling(), 0)
566 self.assertFalse(t.cancelled()) # Task is still not complete
567
568 # Cancel second sleep
569 self.assertTrue(t.cancel())
570 self.assertEqual(t.cancelling(), 1)
571 self.assertFalse(t.cancelled()) # Task is still not complete
572 with self.assertRaises(asyncio.CancelledError):
573 loop.run_until_complete(t)
574 self.assertTrue(t.cancelled()) # Finally, task complete
575 self.assertTrue(t.done())
576
577 # uncancel is no longer effective after the task is complete
578 t.uncancel()
579 self.assertTrue(t.cancelled())
580 self.assertTrue(t.done())
581 finally:
582 loop.close()
583
584 def test_uncancel_structured_blocks(self):
585 # This test recreates the following high-level structure using uncancel()::

Callers

nothing calls this directly

Calls 15

new_taskMethod · 0.95
taskFunction · 0.85
assertTrueMethod · 0.80
assertInMethod · 0.80
cancellingMethod · 0.80
assertFalseMethod · 0.80
assertNotInMethod · 0.80
uncancelMethod · 0.80
new_event_loopMethod · 0.45
run_until_completeMethod · 0.45
sleepMethod · 0.45
cancelMethod · 0.45

Tested by

no test coverage detected