Keyboard interruption for BoxesServer

This commit is contained in:
Vojtěch Mrkývka 2022-08-28 11:24:21 +02:00 committed by Florian Festi
parent cd4949ccac
commit 224f7b25aa
1 changed files with 11 additions and 2 deletions

View File

@ -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) )
try:
httpd.serve_forever() httpd.serve_forever()
except KeyboardInterrupt:
fc.stop()
httpd.server_close()
print("BoxesServer stops.")
else: else:
application = BServer().serve application = BServer().serve