Skip to content
Snippets Groups Projects
Commit 41cda9ab authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add SIGTERM handling

Properly stop the server when receiving a SIGTERM
parent 51d692b2
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import epics
import time
import json
import os
import signal
import matplotlib.pyplot as plt
from io import BytesIO
from git import Repo
......@@ -484,6 +485,14 @@ class myHandler(BaseHTTPRequestHandler):
self.wfile.write(bytes('The server is running', "utf-8"))
return
def on_exit(signum, frame):
print(f'Signal handler called with signal {signum}')
raise SystemExit("Exiting")
signal.signal(signal.SIGTERM, on_exit)
try:
epicsThread = epicsQuery(stop_signal)
epicsThread.start()
......@@ -491,7 +500,7 @@ try:
print ('Started httpserver on port ' , PORT_NUMBER)
server.serve_forever()
except KeyboardInterrupt:
except (KeyboardInterrupt, SystemExit):
print ('\n^C received, shutting down the web server')
server.socket.close()
stop_signal.set()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment