tornadoweb / tornado

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
http://www.tornadoweb.org/
Apache License 2.0
21.77k stars 5.51k forks source link

run_sync raises TimeoutError on explicit event-loop stop #3435

Open minrk opened 4 weeks ago

minrk commented 4 weeks ago

When a coroutine passed to run_sync doesn't finish because the event loop is stopped explicitly, the error raised is a somewhat confusing:

TimeoutError: Operation timed out after None seconds

Repro:

import asyncio
from tornado.ioloop import IOLoop

async def main():
    await asyncio.sleep(1)
    # ask the loop to stop
    IOLoop.current().stop()
    # coroutine doesn't finish
    await asyncio.sleep(10)

if __name__ == "__main__":
    IOLoop.current().run_sync(main)

I'm not even sure it needs to not be a TimeoutError, but the message should probably at least distinguish between the timeout having triggered and the loop stopping for other reasons. Right now, this bit assumes a timeout is the only way the loop might stop before the given coroutine exits.