mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 08:53:37 +00:00
Improved startup and shutdown for tornado
This commit is contained in:
parent
149d7b29df
commit
6dd78f58b6
2 changed files with 20 additions and 36 deletions
|
@ -368,12 +368,12 @@ def main():
|
||||||
logger.log(u"Loading initial show list")
|
logger.log(u"Loading initial show list")
|
||||||
loadShowsFromDB()
|
loadShowsFromDB()
|
||||||
|
|
||||||
|
# start tornado thread
|
||||||
|
sickbeard.WEBSERVER.start()
|
||||||
|
|
||||||
# Fire up all our threads
|
# Fire up all our threads
|
||||||
sickbeard.start()
|
sickbeard.start()
|
||||||
|
|
||||||
# start tornado thread
|
|
||||||
sickbeard.WEBSERVER.thread.start()
|
|
||||||
|
|
||||||
# Launch browser if we're supposed to
|
# Launch browser if we're supposed to
|
||||||
if sickbeard.LAUNCH_BROWSER and not noLaunch and not sickbeard.DAEMON:
|
if sickbeard.LAUNCH_BROWSER and not noLaunch and not sickbeard.DAEMON:
|
||||||
sickbeard.launchBrowser(startPort)
|
sickbeard.launchBrowser(startPort)
|
||||||
|
|
|
@ -150,43 +150,27 @@ class webserverInit():
|
||||||
|
|
||||||
self.server.listen(self.options['port'], self.options['host'])
|
self.server.listen(self.options['port'], self.options['host'])
|
||||||
|
|
||||||
|
def start(self):
|
||||||
if self.thread == None or not self.thread.isAlive():
|
if self.thread == None or not self.thread.isAlive():
|
||||||
self.thread = threading.Thread(None, self.monitor, 'TORNADO')
|
self.thread = threading.Thread(None, IOLoop.current().start, 'TORNADO')
|
||||||
|
self.thread.start()
|
||||||
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)
|
|
||||||
|
|
||||||
def shutdown(self):
|
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()
|
IOLoop.instance().stop()
|
||||||
|
|
||||||
|
# stop tornado thread
|
||||||
|
try:
|
||||||
self.thread.join(10)
|
self.thread.join(10)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
logger.log('Tornado is now shutdown')
|
# stop tornado http server
|
||||||
|
self.server.stop()
|
||||||
|
|
||||||
|
# remove thread object
|
||||||
|
self.thread = None
|
Loading…
Reference in a new issue