From 199c17e2c1d6218e9cfbef8668190403ce40ea04 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 14 Jan 2012 20:55:23 +0100 Subject: [PATCH] Better shutdown and restart --- CouchPotato.py | 2 +- couchpotato/core/_base/_core/main.py | 4 ++++ couchpotato/runner.py | 7 ------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CouchPotato.py b/CouchPotato.py index f4083f6..68922c6 100755 --- a/CouchPotato.py +++ b/CouchPotato.py @@ -59,5 +59,5 @@ if __name__ == '__main__': from couchpotato.core.event import fireEvent fireEvent('app.crappy_shutdown', single = True) - time.sleep(1) + time.sleep(0.1) sys.exit() diff --git a/couchpotato/core/_base/_core/main.py b/couchpotato/core/_base/_core/main.py index 162f73c..0f75a3b 100644 --- a/couchpotato/core/_base/_core/main.py +++ b/couchpotato/core/_base/_core/main.py @@ -46,6 +46,7 @@ class Core(Plugin): self.urlopen('%sapp.shutdown' % self.createApiUrl(), show_error = False) return True except: + self.initShutdown() return False def crappyRestart(self): @@ -53,6 +54,7 @@ class Core(Plugin): self.urlopen('%sapp.restart' % self.createApiUrl(), show_error = False) return True except: + self.initShutdown(restart = True) return False def shutdown(self): @@ -89,6 +91,8 @@ class Core(Plugin): try: request.environ.get('werkzeug.server.shutdown')() + except RuntimeError: + pass except: log.error('Failed shutting down the server: %s' % traceback.format_exc()) diff --git a/couchpotato/runner.py b/couchpotato/runner.py index 9596287..d1b7fdd 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -8,9 +8,7 @@ from werkzeug.contrib.cache import FileSystemCache import locale import logging import os.path -import socket import sys -import time import traceback def getOptions(base_path, args): @@ -189,11 +187,6 @@ def runCouchPotato(options, base_path, args, handle = None): # Go go go! try: app.run(**config) - except socket.error: - log.error('Something else is running on the same address') - time.sleep(3) - app.run(**config) - log.error('Something else is running on the same address222') except (KeyboardInterrupt, SystemExit): raise except: