[Async-sig] killing tasks that won't cancel

Yury Selivanov yselivanov at gmail.com
Tue Feb 19 15:33:41 EST 2019



> On Feb 19, 2019, at 3:23 PM, Chris Jerdonek <chris.jerdonek at gmail.com> wrote:
> 
> On Tue, Feb 19, 2019 at 12:10 PM Andrew Svetlov
> <andrew.svetlov at 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


More information about the Async-sig mailing list