Keyboard interruption for BoxesServer
This commit is contained in:
parent
cd4949ccac
commit
224f7b25aa
|
@ -45,6 +45,7 @@ class FileChecker(threading.Thread):
|
||||||
super(FileChecker, self).__init__()
|
super(FileChecker, self).__init__()
|
||||||
self.checkmodules = checkmodules
|
self.checkmodules = checkmodules
|
||||||
self.timestamps = {}
|
self.timestamps = {}
|
||||||
|
self._stopped = False
|
||||||
for path in files:
|
for path in files:
|
||||||
self.timestamps[path] = os.stat(path).st_mtime
|
self.timestamps[path] = os.stat(path).st_mtime
|
||||||
if checkmodules:
|
if checkmodules:
|
||||||
|
@ -70,11 +71,14 @@ class FileChecker(threading.Thread):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while not self._stopped:
|
||||||
if not self.filesOK():
|
if not self.filesOK():
|
||||||
os.execv(__file__, sys.argv)
|
os.execv(__file__, sys.argv)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._stopped = True
|
||||||
|
|
||||||
class ArgumentParserError(Exception): pass
|
class ArgumentParserError(Exception): pass
|
||||||
|
|
||||||
class ThrowingArgumentParser(argparse.ArgumentParser):
|
class ThrowingArgumentParser(argparse.ArgumentParser):
|
||||||
|
@ -554,7 +558,12 @@ if __name__=="__main__":
|
||||||
boxserver = BServer()
|
boxserver = BServer()
|
||||||
httpd = make_server(host, port, boxserver.serve)
|
httpd = make_server(host, port, boxserver.serve)
|
||||||
print("BoxesServer serving on host:port %s:%s..." % (host, port) )
|
print("BoxesServer serving on host:port %s:%s..." % (host, port) )
|
||||||
httpd.serve_forever()
|
try:
|
||||||
|
httpd.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
fc.stop()
|
||||||
|
httpd.server_close()
|
||||||
|
print("BoxesServer stops.")
|
||||||
else:
|
else:
|
||||||
application = BServer().serve
|
application = BServer().serve
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue