-
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
'Restarting' tornado keeps old application/handlers active #2523
Comments
My guess is that the browser re-used the same connection "keep-alive" and that connection on the tornado side retained its reference to the old server instance/objects. |
@ploxiln , your conjecture is absolutely correct. This question has been bothering me for a few days. Thank you for helping me find the answer. |
Thanks a lot, I guess there are still connections open that need to be closed, I'll try to see if I can get it to work with this information! |
@maartenbreddels , it seems that you need to explicitly close all current connections after you stop the http server. Here's an example from the test code: Lines 446 to 451 in cc2cf07
|
Great timing @garenchan, felt like pair-programming. def stop_tornado():
ioloop = tornado.ioloop.IOLoop.current()
ioloop.add_future(server.close_all_connections(), lambda x: ioloop.stop())
print("Asked Tornado to exit") This seems to work nicely, I'll see if that resolves my original issue, if so, I'll close this. |
thanks for investigating the details @garenchan , it's an interesting case |
Generally, you should stop the server first, that is, close all listening sockets. Then close all connections. This can shut down the server as quickly as possible! If you close the connections first and new connections are established at the same time, close_all_connections may never be completed. |
@garenchan again, are we pair programming? :) #! /usr/bin/env python
import tornado.ioloop
import tornado.web
import time
import datetime
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world!\n")
class MainHandler2(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world2!\n")
def start_app(*args, **kwargs):
global server
application = tornado.web.Application([
(r"/", MainHandler),
])
server = application.listen(7888)
print("Starting app")
return server
def start_app2(*args, **kwargs):
global server2
application = tornado.web.Application([
(r"/", MainHandler2),
])
server2 = application.listen(7888)
print("Starting app2")
return server
def stop_tornado():
server.stop()
ioloop = tornado.ioloop.IOLoop.current()
ioloop.add_future(server.close_all_connections(), lambda x: ioloop.stop())
print("Asked Tornado to exit")
def main():
server = start_app()
tornado.ioloop.IOLoop.current().add_timeout(
datetime.timedelta(seconds=10),
stop_tornado)
tornado.ioloop.IOLoop.current().start()
print("Tornado finished")
# Starting over
start_app2()
tornado.ioloop.IOLoop.current().start()
main() (PS: don't use globals in real life) |
@maartenbreddels , I think we're doing pair programming! The code you gave is good enough for me. |
Thanks, my original issue in jupyter/nbconvert#901 is now fully solved, thanks! |
I want to ask that how to clear all the cache or old application/handlers in async way in this: async def stop_serverI tried but not works for me. |
Thanks for the awesome library, have been using it for years now, and I can usually solve issues with all the resources around, but now I'm stuck.
Based on this answer, I expected this snippet:
To answer 'Hello, world!' for ~10 seconds, and after printing 'Starting app2' to answer 'Hello world2!'. However, it keeps the old handlers active it seems. Is this supported, maybe a bug, and is there a workaround?
I need this because i start a server to make the browser do something, then I close the server, and later on, an external library might start the server again. Since it hosts files from a tempdir, I see 404s (since the files are deleted). I think I've reduced my issue to this example here.
The text was updated successfully, but these errors were encountered: