PyO3 / tokio

Asyncio event loop written in Rust language
Other
245 stars 12 forks source link

asyncio.Task.current_task() returns None #54

Open diefans opened 7 years ago

diefans commented 7 years ago

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())
fafhrd91 commented 7 years ago

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 commented 7 years ago

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

1st1 commented 7 years ago

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.