Browse Source

linting

main
Michael Pilosov 2 years ago
parent
commit
fe15bbbf1e
  1. 19
      src/announce_server/client.py
  2. 10
      src/announce_server/server.py

19
src/announce_server/client.py

@ -1,12 +1,13 @@
import asyncio
import argparse import argparse
import asyncio
import signal import signal
import threading import threading
from http.server import HTTPServer, SimpleHTTPRequestHandler from http.server import HTTPServer, SimpleHTTPRequestHandler
import socketio
from .decorator import register_service from .decorator import register_service
from .get_ip import get_ip_address from .get_ip import get_ip_address
import socketio
sio = socketio.AsyncClient() sio = socketio.AsyncClient()
@ -99,10 +100,17 @@ def exit_handler(sig, frame):
# except (KeyboardInterrupt, asyncio.exceptions.CancelledError): # except (KeyboardInterrupt, asyncio.exceptions.CancelledError):
# print("Cleaning up and shutting down...") # print("Cleaning up and shutting down...")
def start_client(host_ip="0.0.0.0", host_port=4999): 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): 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}/) ...") print(f"Serving HTTP on 0.0.0.0 port {port} (http://0.0.0.0:{port}/) ...")
def serve_forever_nonblocking(): 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.SIGINT, exit_handler)
signal.signal(signal.SIGTERM, exit_handler) signal.signal(signal.SIGTERM, exit_handler)
try: try:
server_thread = server() server_thread = server()
asyncio.run(main(host_ip, host_port)) asyncio.run(main(host_ip, host_port))

10
src/announce_server/server.py

@ -143,7 +143,7 @@ def start_server(address, port, heartbeat_interval, heartbeat_timeout):
# heartbeat(sio, heartbeat_interval, heartbeat_timeout) # heartbeat(sio, heartbeat_interval, heartbeat_timeout)
# ) # )
# aiohttp_app = loop.create_task(web._run_app(app, host=address, port=port)) # aiohttp_app = loop.create_task(web._run_app(app, host=address, port=port))
# Python 3.6+ compatible. Supports any awaitable: # Python 3.6+ compatible. Supports any awaitable:
heartbeat_task = asyncio.ensure_future( heartbeat_task = asyncio.ensure_future(
heartbeat(sio, heartbeat_interval, heartbeat_timeout) heartbeat(sio, heartbeat_interval, heartbeat_timeout)
@ -166,10 +166,8 @@ def start_server(address, port, heartbeat_interval, heartbeat_timeout):
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Start announce_server client.") parser = argparse.ArgumentParser(description="Start announce_server client.")
parser.add_argument( parser.add_argument("--ip", default="0.0.0.0", help="IP address of the host server")
"--ip", default="0.0.0.0", help="IP address of the host server"
)
parser.add_argument( parser.add_argument(
"--port", default=4999, type=int, help="Port of the host server" "--port", default=4999, type=int, help="Port of the host server"
) )
@ -185,7 +183,7 @@ if __name__ == "__main__":
type=float, type=float,
help="Heartbeat timeout in seconds", help="Heartbeat timeout in seconds",
) )
args = parser.parse_args() args = parser.parse_args()
start_server( start_server(

Loading…
Cancel
Save