From fe15bbbf1e999960ae98d2dda2350c1d9fd4a529 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Sun, 19 Mar 2023 23:09:49 -0600 Subject: [PATCH] linting --- src/announce_server/client.py | 19 +++++++++++++------ src/announce_server/server.py | 10 ++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/announce_server/client.py b/src/announce_server/client.py index 5a327d1..292e9c3 100644 --- a/src/announce_server/client.py +++ b/src/announce_server/client.py @@ -1,12 +1,13 @@ -import asyncio import argparse +import asyncio import signal import threading - from http.server import HTTPServer, SimpleHTTPRequestHandler + +import socketio + from .decorator import register_service from .get_ip import get_ip_address -import socketio sio = socketio.AsyncClient() @@ -99,10 +100,17 @@ def exit_handler(sig, frame): # 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", ip=get_ip_address(), port=13373, host_ip=host_ip, host_port=host_port) + @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) + 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(): @@ -121,7 +129,6 @@ def start_client(host_ip="0.0.0.0", host_port=4999): signal.signal(signal.SIGINT, exit_handler) signal.signal(signal.SIGTERM, exit_handler) - try: server_thread = server() asyncio.run(main(host_ip, host_port)) diff --git a/src/announce_server/server.py b/src/announce_server/server.py index 0e6a45a..1697dd1 100644 --- a/src/announce_server/server.py +++ b/src/announce_server/server.py @@ -143,7 +143,7 @@ def start_server(address, port, heartbeat_interval, heartbeat_timeout): # heartbeat(sio, heartbeat_interval, heartbeat_timeout) # ) # aiohttp_app = loop.create_task(web._run_app(app, host=address, port=port)) - + # Python 3.6+ compatible. Supports any awaitable: heartbeat_task = asyncio.ensure_future( heartbeat(sio, heartbeat_interval, heartbeat_timeout) @@ -166,10 +166,8 @@ def start_server(address, port, heartbeat_interval, heartbeat_timeout): if __name__ == "__main__": parser = argparse.ArgumentParser(description="Start announce_server client.") - - parser.add_argument( - "--ip", default="0.0.0.0", help="IP address of the host server" - ) + + parser.add_argument("--ip", default="0.0.0.0", help="IP address of the host server") parser.add_argument( "--port", default=4999, type=int, help="Port of the host server" ) @@ -185,7 +183,7 @@ if __name__ == "__main__": type=float, help="Heartbeat timeout in seconds", ) - + args = parser.parse_args() start_server(