diff --git a/examples/websocket-service/start_web_server.py b/examples/websocket-service/start_web_server.py index 1ecb1b6..b794edb 100755 --- a/examples/websocket-service/start_web_server.py +++ b/examples/websocket-service/start_web_server.py @@ -40,9 +40,8 @@ def signal_handler(sig, frame): """Handle Ctrl+C gracefully.""" print("\nšŸ‘‹ Shutting down...") if httpd: + # Use shutdown() to stop serve_forever() httpd.shutdown() - httpd.server_close() - sys.exit(0) def main(): @@ -75,15 +74,16 @@ def main(): ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā• """) - with socketserver.TCPServer((args.host, args.port), CustomHandler) as httpd: - print(f"šŸš€ Server started on http://{args.host}:{args.port}") - try: - httpd.serve_forever() - except KeyboardInterrupt: - pass - finally: - print("\nšŸ‘‹ Server stopped") - httpd.server_close() + httpd = socketserver.TCPServer((args.host, args.port), CustomHandler) + print(f"šŸš€ Server started on http://{args.host}:{args.port}") + + try: + httpd.serve_forever() + except KeyboardInterrupt: + pass + finally: + print("\nšŸ‘‹ Server stopped") + httpd.server_close() if __name__ == "__main__":