|
@ -33,74 +33,6 @@ async def main(host_ip, host_port): |
|
|
await sio.wait() |
|
|
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): |
|
|
def start_client(host_ip="0.0.0.0", host_port=4999): |
|
|
@register_service( |
|
|
@register_service( |
|
|
name="test client", |
|
|
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}/) ...") |
|
|
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(): |
|
|
while not server_should_exit.is_set(): |
|
|
httpd.handle_request() |
|
|
httpd.handle_request() |
|
|
|
|
|
|
|
|
|
|
|
httpd.shutdown() |
|
|
httpd.shutdown() |
|
|
httpd.server_close() |
|
|
httpd.server_close() |
|
@ -125,10 +56,6 @@ def start_client(host_ip="0.0.0.0", host_port=4999): |
|
|
|
|
|
|
|
|
return server_thread |
|
|
return server_thread |
|
|
|
|
|
|
|
|
server_should_exit = threading.Event() |
|
|
|
|
|
signal.signal(signal.SIGINT, 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)) |
|
@ -136,8 +63,6 @@ def start_client(host_ip="0.0.0.0", host_port=4999): |
|
|
print("Cleaning up and shutting down...") |
|
|
print("Cleaning up and shutting down...") |
|
|
finally: |
|
|
finally: |
|
|
print("Shutting down test client...") |
|
|
print("Shutting down test client...") |
|
|
server_should_exit.set() |
|
|
|
|
|
# server_thread.join() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|