summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2009-12-20 20:55:50 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2009-12-20 20:55:50 +0100
commit83b46c1564ec4372de7386d677f108bd472c00b7 (patch)
tree4a2b27ea323b1a21bd14f113bc468d679e0a384e
parentwebinterface - design 70% (diff)
parentfixed file_list again, webserver terminates correctly when killing pyload ove... (diff)
downloadpyload-83b46c1564ec4372de7386d677f108bd472c00b7.tar.xz
merge
-rw-r--r--module/web/ServerThread.py16
-rwxr-xr-xpyLoadCore.py13
2 files changed, 19 insertions, 10 deletions
diff --git a/module/web/ServerThread.py b/module/web/ServerThread.py
index 6113ac297..2279296d8 100644
--- a/module/web/ServerThread.py
+++ b/module/web/ServerThread.py
@@ -1,21 +1,27 @@
#!/usr/bin/env python
import threading
from os.path import join
-import subprocess
+from subprocess import Popen, PIPE, STDOUT
+from time import sleep
+from signal import SIGINT
class WebServer(threading.Thread):
def __init__(self, pycore):
threading.Thread.__init__(self)
self.pycore = pycore
+ self.running = True
self.setDaemon(True)
def run(self):
host = self.pycore.config['webinterface']['host']
port = self.pycore.config['webinterface']['port']
self.pycore.logger.info("Starting Webserver: %s:%s" % (host,port) )
- try:
- subprocess.call(['python',join(self.pycore.path,"module","web","manage.py"), "runserver", "%s:%s" % (host,port)], close_fds=True)
- except Exception, e:
- print e
+ self.p = Popen(['python',join(self.pycore.path,"module","web","manage.py"), "runserver", "%s:%s" % (host,port)], close_fds=True, stderr=PIPE, stdin=PIPE, stdout=PIPE, shell=True)
#os.system("python " + join(self.pycore.path,"module","web","manage.py runserver %s:%s" % (host,port)))
#@TODO: better would be real python code
+ while self.running:
+ sleep(1)
+
+ def quit(self):
+ self.p.terminate()
+ self.running = False
diff --git a/pyLoadCore.py b/pyLoadCore.py
index fbce78aaf..50c5d2c55 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -158,8 +158,11 @@ class Core(object):
while True:
sleep(2)
- if self.do_kill:
- raise KeyboardInterrupt
+ if self.do_kill:
+ self.logger.info("pyLoad quits")
+ self.webserver.quit()
+ self.webserver.join()
+ exit()
def init_server(self):
try:
@@ -421,12 +424,12 @@ class ServerMethods():
try:
self.core.file_list.collector.removeFile(id)
except:
- self.core.file_list.packages.removeFile(id)
+ self.core.file_list.packager.removeFile(id)
self.core.file_list.save()
def del_packages(self, ids):
for id in ids:
- self.core.file_list.packages.removePackage(id)
+ self.core.file_list.packager.removePackage(id)
self.core.file_list.save()
def kill(self):
@@ -488,6 +491,6 @@ if __name__ == "__main__":
try:
pyload_core.start()
except KeyboardInterrupt:
- pyload_core.logger.info("killed pyLoad")
+ pyload_core.logger.info("killed pyLoad by Terminal")
exit()