Skip to content

Commit

Permalink
Always stop the server when exiting serve()
Browse files Browse the repository at this point in the history
Closes #264
bcb committed May 31, 2023
1 parent 75cee0e commit 9a1fe9f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion jsonrpcserver/server.py
Original file line number Diff line number Diff line change
@@ -25,4 +25,11 @@ def do_POST(self) -> None: # pylint: disable=invalid-name
def serve(name: str = "", port: int = 5000) -> None:
"""A simple function to serve HTTP requests"""
logging.info(" * Listening on port %s", port)
HTTPServer((name, port), RequestHandler).serve_forever()
try:
httpd = HTTPServer((name, port), RequestHandler)
httpd.serve_forever()
except KeyboardInterrupt:
pass
except Exception:
httpd.shutdown()
raise

0 comments on commit 9a1fe9f

Please sign in to comment.