tokio icon indicating copy to clipboard operation
tokio copied to clipboard

asyncio.Task.current_task() returns None

Open diefans opened this issue 8 years ago • 3 comments

If I register a signal handler within a task to cancel itself, tokio failes with: AttributeError: 'NoneType' object has no attribute 'cancel'

async def test_tokio_failes():
    current_task = asyncio.Task.current_task()
    asyncio.get_event_loop().add_signal_handler(signal.SIGINT, current_task.cancel)

def main():
    # ...
    loop.run_until_complete(test_tokio_failes())

diefans avatar Aug 03 '17 09:08 diefans

This api is broken. There is no way to override it in asyncio. You can use loop.current_task() There are plans to change add current_task() to asyncio

fafhrd91 avatar Aug 03 '17 14:08 fafhrd91

@1st1 btw do we have plans to add current_task() to event loop?

fafhrd91 avatar Aug 03 '17 16:08 fafhrd91

Yes, we do, after I finish on my current PEP, I'll switch to working on a PEP for asyncio improvements in 3.7. loop.current_task() will be a part of it.

1st1 avatar Aug 03 '17 16:08 1st1