Simulate edge cancellation #680
Unanswered
davidbrochart
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I often want to be able to cancel an individual task, and have something that looks like asyncio's edge cancellation API, while keeping the advantages of structured concurrency.
In AnyIO this means creating a task group just for that task, but since this operation is async, one has to await the creation of the task group before being able to cancel the task, which is not the case in asyncio where launching and cancelling a task can be done in non-async functions:
The following
Cancellable
class is close to asyncio's API, but cancelling needs to be awaited:And the following version has a non-async cancellation:
I'm not sure this is the right way to do it, maybe I'm missing something simpler?
Do you think simulating edge cancellation is not a good idea in the first place?
Beta Was this translation helpful? Give feedback.
All reactions