![](https://secure.gravatar.com/avatar/60a2f1855ca0d8aac3fa75a57233a3f1.jpg?s=120&d=mm&r=g)
On Feb 19, 2019, at 3:23 PM, Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
On Tue, Feb 19, 2019 at 12:10 PM Andrew Svetlov <andrew.svetlov@gmail.com> wrote:
If the task's function swallows CancelledError exception -- it is a programming error.
I was asking if there is a way to end such a task. Is there? The only approach I can think of without having something like set_exception() is to keep calling cancel() in a loop and waiting (but even that can fail under certain code), but I'm not sure off-hand if the API supports calling cancel() more than once.
Unfortunately asyncio isn't super flexible around "cancellation with a timeout" kind of scenarios. The current assumption is that once the cancellation is requested, the Task will start cancelling and will do so in a timely manner. Imposing a second layer of timeouts on the cancellation process itself isn't natively supported. But to properly address this we don't need a very broadly defined Task.set_exception(); we need to rethink the cancellation in asyncio (perhaps draw some inspiration from Trio and other frameworks). Yury