File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -614,10 +614,24 @@ is next scheduled. This mechanism works with nested coros. However there is a
614
614
limitation. If a coro issues ` await uasyncio.sleep(secs) ` or
615
615
` uasyncio.sleep_ms(ms) ` scheduling will not occur until the time has elapsed.
616
616
This introduces latency into cancellation which matters in some use-cases.
617
- Other potential sources of latency take the form of slow code.
617
+ Another source of latency is where a task is waiting on I/O. In many
618
+ applications it is necessary for the task performing cancellation to pause
619
+ until all cancelled coros have actually stopped.
618
620
619
- ` uasyncio ` lacks a mechanism for verifying when cancellation has actually
620
- occurred. The ` asyn ` library provides verification via the following classes:
621
+ If the task to be cancelled only pauses on zero delays and never waits on I/O,
622
+ the round-robin nature of the scheduler avoids the need to verify cancellation:
623
+
624
+ ``` python
625
+ asyncio.cancel(my_coro)
626
+ await asyncio.sleep(0 ) # Ensure my_coro gets scheduled with the exception
627
+ # my_coro will be cancelled now
628
+ ```
629
+ This does require that all coros awaited by ` my_coro ` also meet the zero delay
630
+ criterion.
631
+
632
+ That special case notwithstanding, ` uasyncio ` lacks a mechanism for verifying
633
+ when cancellation has actually occurred. The ` asyn ` library provides
634
+ verification via the following classes:
621
635
622
636
1 . ` Cancellable ` This allows one or more tasks to be assigned to a group. A
623
637
coro can cancel all tasks in the group, pausing until this has been achieved.
You can’t perform that action at this time.
0 commit comments