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 ...@@ -2,6 +2,7 @@ import epics
import time import time
import json import json
import os import os
import signal
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from io import BytesIO from io import BytesIO
from git import Repo from git import Repo
...@@ -484,6 +485,14 @@ class myHandler(BaseHTTPRequestHandler): ...@@ -484,6 +485,14 @@ class myHandler(BaseHTTPRequestHandler):
self.wfile.write(bytes('The server is running', "utf-8")) self.wfile.write(bytes('The server is running', "utf-8"))
return return
def on_exit(signum, frame):
print(f'Signal handler called with signal {signum}')
raise SystemExit("Exiting")
signal.signal(signal.SIGTERM, on_exit)
try: try:
epicsThread = epicsQuery(stop_signal) epicsThread = epicsQuery(stop_signal)
epicsThread.start() epicsThread.start()
...@@ -491,7 +500,7 @@ try: ...@@ -491,7 +500,7 @@ try:
print ('Started httpserver on port ' , PORT_NUMBER) print ('Started httpserver on port ' , PORT_NUMBER)
server.serve_forever() server.serve_forever()
except KeyboardInterrupt: except (KeyboardInterrupt, SystemExit):
print ('\n^C received, shutting down the web server') print ('\n^C received, shutting down the web server')
server.socket.close() server.socket.close()
stop_signal.set() 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