From 5c7e9f0f1325523347a52869cebbf03463550bca Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 24 Dec 2009 01:41:13 +0100 Subject: clean shutdown --- module/thread_list.py | 4 ++++ module/web/ServerThread.py | 5 ++++- pyLoadCore.py | 20 +++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/module/thread_list.py b/module/thread_list.py index 966157b91..fc4160a6d 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -216,6 +216,10 @@ class Thread_List(object): def scripts_reconnected(self, ip): map(lambda script: subprocess.Popen([script, ip], stdout=subprocess.PIPE), self.parent.scripts['download_finished']) + def stopAllDownloads(self): + for pyfile in self.py_downloading: + pyfile.plugin.req.abort = True + class SpeedManager(Thread): def __init__(self, parent): Thread.__init__(self) diff --git a/module/web/ServerThread.py b/module/web/ServerThread.py index 0d6044562..069cabafe 100644 --- a/module/web/ServerThread.py +++ b/module/web/ServerThread.py @@ -36,7 +36,10 @@ class WebServer(threading.Thread): def quit(self): if os.name == 'posix': - os.kill(self.pid, SIGINT) + try: + os.kill(self.pid, SIGINT) + except: + pass else: self.p.kill() diff --git a/pyLoadCore.py b/pyLoadCore.py index 85ca5a5fe..c5bf7ed0a 100644 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -161,10 +161,9 @@ class Core(object): while True: sleep(2) - if self.do_kill: + if self.do_kill: + self.shutdown() self.logger.info("pyLoad quits") - self.webserver.quit() - self.webserver.join() exit() def init_server(self): @@ -312,7 +311,17 @@ class Core(object): else: return False def getMaxSpeed(self): - return self.downloadSpeedLimit + return self.downloadSpeedLimit + + def shutdown(self): + self.logger.info("shutting down...") + self.webserver.quit() + self.webserver.join() + self.thread_list.stopAllDownloads() + for thread in self.thread_list.threads: + thread.shutdown = True + thread.join(15) + self.file_list.save() #################################### ########## XMLRPC Methods ########## @@ -511,7 +520,8 @@ if __name__ == "__main__": pyload_core = Core() try: pyload_core.start() - except KeyboardInterrupt: + except KeyboardInterrupt: + pyload_core.shutdown() pyload_core.logger.info("killed pyLoad by Terminal") exit() -- cgit v1.2.3