From 661c4ed6a7077b0ebe8f0850fa175d7f26e7cacb Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 15 Jun 2014 00:30:10 -0700 Subject: [PATCH] Small fix for shutdown issues --- sickbeard/webserveInit.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/sickbeard/webserveInit.py b/sickbeard/webserveInit.py index 775822b3..5202b683 100644 --- a/sickbeard/webserveInit.py +++ b/sickbeard/webserveInit.py @@ -180,21 +180,23 @@ class webserverInit(): logger.logging.info('Shutting down tornado') + self.abort = True + self.server.stop() + + deadline = time.time() + 3 + + io_loop = IOLoop.instance() + + def stop_loop(): + now = time.time() + if now < deadline and (io_loop._callbacks or io_loop._timeouts): + io_loop.add_timeout(now + 1, stop_loop) + else: + io_loop.stop() + + stop_loop() + try: - self.abort = True - self.server.stop() - - deadline = time.time() + 10 - - io_loop = IOLoop.instance() - def stop_loop(): - now = time.time() - - if now < deadline: - if io_loop._callbacks: - io_loop.add_timeout(now + 1, stop_loop) - return - stop_loop() self.thread.join(10) except: pass