tokio
tokio copied to clipboard
asyncio.Task.current_task() returns None
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())
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
@1st1 btw do we have plans to add current_task() to event loop?
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.