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')
try:
# stop tornado io loop
IOLoop.instance().stop()
# stop tornado thread
try:
self.thread.join(10)
except:
pass
logger.log('Tornado is now shutdown')
# stop tornado http server
self.server.stop()
# remove thread object
self.thread = None