From 945f485243a72dabe0ef205939554448dcdc6ca7 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Sun, 19 Mar 2023 23:14:48 -0600 Subject: [PATCH] REFACTOR/CLEANUP start_client --- src/announce_server/client.py | 77 +---------------------------------- 1 file changed, 1 insertion(+), 76 deletions(-) diff --git a/src/announce_server/client.py b/src/announce_server/client.py index 292e9c3..70f2250 100644 --- a/src/announce_server/client.py +++ b/src/announce_server/client.py @@ -33,74 +33,6 @@ async def main(host_ip, host_port): await sio.wait() -def exit_handler(sig, frame): - global server_should_exit - server_should_exit.set() - - -# def start_client(host_ip="0.0.0.0", host_port=4999): -# @register_service(name="test client", ip=get_ip_address(), port=13373, host_ip=host_ip, host_port=host_port) -# def server(port=13373): -# global server_should_exit -# server_should_exit = threading.Event() - -# httpd = HTTPServer(('', port), SimpleHTTPRequestHandler) -# print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...") - -# def serve_forever_nonblocking(): -# while not server_should_exit.is_set(): -# httpd.handle_request() - -# server_thread = threading.Thread(target=serve_forever_nonblocking) -# server_thread.start() - - -# return server_thread - -# signal.signal(signal.SIGINT, exit_handler) -# signal.signal(signal.SIGTERM, exit_handler) - -# server_thread = server() - -# try: -# asyncio.run(main(host_ip, host_port)) -# finally: -# print("Shutting down test client...") -# server_should_exit.set() -# # server_thread.join() - -# def start_client(host_ip="0.0.0.0", host_port=4999): -# @register_service(name="test client", ip=get_ip_address(), port=13373, host_ip=host_ip, host_port=host_port) -# def server(port=13373): -# httpd = HTTPServer(('', port), SimpleHTTPRequestHandler) -# print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...") -# httpd.serve_forever() - -# async def cleanup_and_shutdown(): -# try: -# server() -# except KeyboardInterrupt: -# print("Cleaning up and shutting down...") - -# loop = asyncio.get_event_loop() -# loop.run_until_complete(cleanup_and_shutdown()) - -# def start_client(host_ip="0.0.0.0", host_port=4999): -# @register_service(name="test client", ip=get_ip_address(), port=13373, host_ip=host_ip, host_port=host_port) -# def server(port=13373): -# httpd = HTTPServer(('', port), SimpleHTTPRequestHandler) -# print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...") -# httpd.serve_forever() - -# signal.signal(signal.SIGINT, exit_handler) -# signal.signal(signal.SIGTERM, exit_handler) - -# try: -# server() -# except (KeyboardInterrupt, asyncio.exceptions.CancelledError): -# print("Cleaning up and shutting down...") - - def start_client(host_ip="0.0.0.0", host_port=4999): @register_service( name="test client", @@ -114,8 +46,7 @@ def start_client(host_ip="0.0.0.0", host_port=4999): print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...") def serve_forever_nonblocking(): - while not server_should_exit.is_set(): - httpd.handle_request() + httpd.handle_request() httpd.shutdown() httpd.server_close() @@ -125,10 +56,6 @@ def start_client(host_ip="0.0.0.0", host_port=4999): return server_thread - server_should_exit = threading.Event() - signal.signal(signal.SIGINT, exit_handler) - signal.signal(signal.SIGTERM, exit_handler) - try: server_thread = server() asyncio.run(main(host_ip, host_port)) @@ -136,8 +63,6 @@ def start_client(host_ip="0.0.0.0", host_port=4999): print("Cleaning up and shutting down...") finally: print("Shutting down test client...") - server_should_exit.set() - # server_thread.join() if __name__ == "__main__":