Commit b86a6648 authored by JackV's avatar JackV
Browse files

deploy.py: kill the http server before closing the application

parent 21c41571
...@@ -20,10 +20,14 @@ parser.add_argument('--show', action='store_true', default=False, ...@@ -20,10 +20,14 @@ parser.add_argument('--show', action='store_true', default=False,
arg = parser.parse_args() arg = parser.parse_args()
def httpd_t(): class stoppable_httpd(Thread):
def run(self):
print("Serving at http://{}:{}".format(DEFAULT_ADDR, arg.port)) print("Serving at http://{}:{}".format(DEFAULT_ADDR, arg.port))
s = TCPServer((DEFAULT_ADDR, arg.port), Handler) self.s = TCPServer((DEFAULT_ADDR, arg.port), Handler)
s.serve_forever() self.s.serve_forever()
def stop(self):
self.s.shutdown()
def show(): def show():
...@@ -31,8 +35,7 @@ def show(): ...@@ -31,8 +35,7 @@ def show():
if __name__ == '__main__': if __name__ == '__main__':
httpd = Thread(target=httpd_t) httpd = stoppable_httpd()
httpd.daemon = True
httpd.start() httpd.start()
if arg.show: if arg.show:
...@@ -42,4 +45,5 @@ if __name__ == '__main__': ...@@ -42,4 +45,5 @@ if __name__ == '__main__':
while True: while True:
sleep(60 * 60 * 24) sleep(60 * 60 * 24)
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
httpd.stop()
sys.exit(0) sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment