Skip to content

Commit 9a1fe9f

Browse files
committed
Always stop the server when exiting serve()
Closes #264
1 parent 75cee0e commit 9a1fe9f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

jsonrpcserver/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,11 @@ def do_POST(self) -> None: # pylint: disable=invalid-name
2525
def serve(name: str = "", port: int = 5000) -> None:
2626
"""A simple function to serve HTTP requests"""
2727
logging.info(" * Listening on port %s", port)
28-
HTTPServer((name, port), RequestHandler).serve_forever()
28+
try:
29+
httpd = HTTPServer((name, port), RequestHandler)
30+
httpd.serve_forever()
31+
except KeyboardInterrupt:
32+
pass
33+
except Exception:
34+
httpd.shutdown()
35+
raise

0 commit comments

Comments
 (0)