1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 11:02:21 -05:00

Improved startup and shutdown for tornado

This commit is contained in:
echel0n 2014-06-15 01:51:35 -07:00
parent 149d7b29df
commit 6dd78f58b6
2 changed files with 20 additions and 36 deletions

View File

@ -368,12 +368,12 @@ def main():
logger.log(u"Loading initial show list")
loadShowsFromDB()
# start tornado thread
sickbeard.WEBSERVER.start()
# Fire up all our threads
sickbeard.start()
# start tornado thread
sickbeard.WEBSERVER.thread.start()
# Launch browser if we're supposed to
if sickbeard.LAUNCH_BROWSER and not noLaunch and not sickbeard.DAEMON:
sickbeard.launchBrowser(startPort)

View File

@ -150,43 +150,27 @@ class webserverInit():
self.server.listen(self.options['port'], self.options['host'])
def start(self):
if self.thread == None or not self.thread.isAlive():
self.thread = threading.Thread(None, self.monitor, 'TORNADO')
def monitor(self):
io_loop = IOLoop.current()
while True:
currentTime = datetime.datetime.now()
if currentTime - self.lastRun > self.cycleTime:
self.lastRun = currentTime
try:
logger.log(u"Starting tornado", logger.DEBUG)
io_loop.start()
except Exception, e:
logger.log(u"Exception generated in tornado: " + ex(e), logger.ERROR)
logger.log(repr(traceback.format_exc()), logger.DEBUG)
if self.abort:
self.abort = False
self.thread = None
return
time.sleep(1)
self.thread = threading.Thread(None, IOLoop.current().start, 'TORNADO')
self.thread.start()
def shutdown(self):
self.abort = True
if self.thread:
logger.log('Shutting down tornado')
logger.log('Shutting down tornado')
try:
# stop tornado io loop
IOLoop.instance().stop()
self.thread.join(10)
except:
pass
logger.log('Tornado is now shutdown')
# stop tornado thread
try:
self.thread.join(10)
except:
pass
# stop tornado http server
self.server.stop()
# remove thread object
self.thread = None