Hi,

When cancelling a task outside of the loop, the task is still considered 
pending because the result (CancelledError) will only be set when the loop 
will try to run the task once more.

In the current version of tulip (last revision from 30 July), a consequence 
of this is that the message "Task was destroyed but it is pending!" can be 
logged, which is not exactly true.

I wrote a test case:

import asyncio

l = asyncio.get_event_loop()

def raise_base_exception():
    raise SystemExit()

@asyncio.coroutine
def coro():
    l.call_soon(raise_base_exception)
    yield from asyncio.sleep(10)

task = asyncio.async(coro())

try:
    l.run_forever()
except BaseException:
    task.cancel()

I'm not sure if the behavior can be considered as a bug in tulip or if it's 
because I rely on a bad design, but in this case I'm sure that when I 
except a BaseException, I don't want to run the loop anymore.

A simple fix for this in tulip would be to set self._log_destroy_pending to 
False when calling cancel().

Cheers,
Martin

Reply via email to