Asyncio tasks getting cancelled

ike at koeln.ccc.de ike at koeln.ccc.de
Mon Nov 5 22:40:51 EST 2018


On Mon, Nov 05, 2018 at 07:15:04PM -0700, Ian Kelly wrote:
> > For context:
> > https://github.com/ldo/dbussy/issues/13
> > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43
> >
> > It really feels like asyncio is loosing strong references to scheduled
> > tasks, as excplicitly keeping them around helps. Also, the error
> > messages I'm getting are the ones from here:
> > https://github.com/python/cpython/blob/16c8a53490a22bd4fcde2efaf4694dd06ded882b/Lib/asyncio/tasks.py#L145
> > Which indicates that the tasks actually weren't even started at all?
> 
> No, it indicates that it was cleaned up (likely because the program
> exited) before the task completed. Which likely implies that the loop
> exited without waiting for it. From the stack trace, you're using
> loop.run_until_complete(main()). Like asyncio.run, that only runs
> until the specific thing you pass it completes, which might wait on
> other things or might not. Anything else that's still pending is going
> to be left up in the air unless you subsequently restart the same
> event loop.

What I meant was, the error message is specific to futures in the
'PENDING' state. Which should be set to 'RUNNING' before any actions
occur. So it appears the tasks weren't started at all.

Also the cleanup happens instantly, ie before the loop exits (as the
main loop has an asyncio.sleep timeout. Printing a message also clearly
shows this happens way before main returns.



More information about the Python-list mailing list