From 36ae1704af800080719f6f1de1f9cf2e9609d3c4 Mon Sep 17 00:00:00 2001 From: joknarf Date: Tue, 24 Dec 2024 15:46:32 +0100 Subject: [PATCH] avoid ConnectionResetError display/with server --- pywebfs/pywebfs.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pywebfs/pywebfs.py b/pywebfs/pywebfs.py index 1d20582..b33f31e 100755 --- a/pywebfs/pywebfs.py +++ b/pywebfs/pywebfs.py @@ -1177,6 +1177,9 @@ def __init__(self, title, certfiles, userp, *args, **kwargs): # server_side=True # ) + def handle_error(self, request, client_address): + return + def log_message(*args): """log message""" @@ -1215,12 +1218,11 @@ def daemon_d(action, pidfilepath, hostname=None, args=None): ) with daemon_context: log_message("Starting server") - server = init_server(hostname, args) - try: - server.serve_forever() - except KeyboardInterrupt: - log_message("Stopping server") - sys.exit(0) + with init_server(hostname, args) as server: + try: + server.serve_forever() + except KeyboardInterrupt: + log_message("Stopping server") def init_server(hostname, args): @@ -1309,13 +1311,12 @@ def main(): if args.action: sys.exit(not daemon_d(args.action, pidfile, hostname, args)) else: - server = init_server(hostname, args) - try: - server.serve_forever() - except KeyboardInterrupt: - log_message("Stopping server") - server.socket.close() - sys.exit(0) + with init_server(hostname, args) as server: + try: + server.serve_forever() + except KeyboardInterrupt: + log_message("Stopping server") + server.socket.close() if __name__ == "__main__":