-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autoreload with asyncio event loop doesn't work #1543
Comments
And as I can see So we can't just add |
I think the right thing to do here is to just swallow any exceptions from |
Hi Ben! Thank you for the idea. Well, may be I'm trying to simplify things, but shouldn't we just swallow all exceptions on auto-reload? I've created a pull request implementing such simple logic, it really worked perfectly. Is it ok? :) |
The snippet bellow seems to work, however. (python 3.5.2, tornado 4.4.2) The only difference is that instead of initializing the event loop using this form: http://www.tornadoweb.org/en/stable/asyncio.html#tornado.platform.asyncio.AsyncIOLoop It uses this form: Anyway, it's kinda hard to tell only from the docs in which circumstances each form is usefull, as the examples seem to be trying to achieve the exact same result. # save this to server.py and run as "python server.py"
import os
import asyncio
import tornado.ioloop
import tornado.httpserver
import tornado.platform.asyncio
import tornado.web
tornado.platform.asyncio.AsyncIOMainLoop().install()
class HomePage(tornado.web.RequestHandler):
def get(self):
self.write("Hello!")
if __name__ == '__main__':
port = 8000
host = '127.0.0.1'
app = tornado.web.Application(
[
(r'/', HomePage),
],
debug=True)
print("Running server at http://%s:%s" % (host, port))
server = tornado.httpserver.HTTPServer(app)
server.bind(port, host)
server.start()
asyncio.get_event_loop().run_forever() |
This was a last-ditch effort to close file descriptors that were not marked as CLOEXEC. However, it was never complete (it didn't touch file descriptors that were not registered on the IOLoop), and it can't work with asyncio (which does not allow closing the IOLoop without stopping it and unwinding the stack first). Since Tornado (and hopefully all major libraries using the IOLoop) is careful about setting CLOEXEC when needed, just get rid of the close. Fixes tornadoweb#1543
#1984 fixes this slightly differently, by skipping the close call completely instead of swallowing exceptions. |
Versions 2.5.2+ have this issue. Downgrade to version 2.5.1 ( |
When running Tornado server in debug mode with autoreload and asyncio event loop the following exception raises:
RuntimeError: Cannot close a running event loop
.Seems like autoreload hook tries to close event loop, but asyncio loop can't be closed without calling
stop()
. Code to reproduce and traceback are below.Steps to reproduce:
The full traceback:
The text was updated successfully, but these errors were encountered: