From fca3fca15fe83d40087d63e63307e6263a70d076 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:48:13 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../_demo/_demo_command_line_interface.py | 25 +++++++++---------- src/tqdm_publisher/_demo/_parallel/_client.py | 8 +++--- src/tqdm_publisher/_demo/_parallel/_server.py | 3 ++- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/tqdm_publisher/_demo/_demo_command_line_interface.py b/src/tqdm_publisher/_demo/_demo_command_line_interface.py index 4a3a372..130e505 100644 --- a/src/tqdm_publisher/_demo/_demo_command_line_interface.py +++ b/src/tqdm_publisher/_demo/_demo_command_line_interface.py @@ -1,13 +1,12 @@ import os +import signal import subprocess import sys +import time from pathlib import Path -from ._server import run_demo as _server from ._parallel._server import run_demo as _parallel_server - -import signal -import time +from ._server import run_demo as _server DEMO_BASE_FOLDER_PATH = Path(__file__).parent @@ -24,11 +23,13 @@ SUBPROCESSES = [] + def close_process(): for process in SUBPROCESSES: process.terminate() # Send SIGTERM to subprocess # sys.exit() + def signal_handler(signal, frame): close_process() @@ -51,7 +52,7 @@ def run_demo(demo, flags): _server() - elif demo == 'parallel-demo': + elif demo == "parallel-demo": if flags["client"]: client_args = ["python", PARALLEL_CLIENT_FILE_PATH] if flags["both"]: @@ -63,12 +64,11 @@ def run_demo(demo, flags): if flags["server"]: if flags["both"]: _parallel_server(flags["host"], flags["port"]) - else: + else: _parallel_server() close_process() - else: print(f"{demo} is an invalid demo option.") @@ -79,9 +79,8 @@ def get_flag(flags, flag, default=None): return flags[flag_index + 1] return default -def _command_line_interface(): - +def _command_line_interface(): """A simple command line interface for running the demo for TQDM Publisher.""" if len(sys.argv) <= 1: print("No input provided. Please specify a command (e.g. 'demo').") @@ -99,7 +98,7 @@ def _command_line_interface(): if len(flags_list) > 0: print(f"No flags are accepted at this time, but flags {flags_list} were received.") return - + client_flag = "--client" in flags_list server_flag = "--server" in flags_list both_flags = "--server" in flags_list and "--client" in flags_list @@ -108,8 +107,8 @@ def _command_line_interface(): client=not server_flag or both_flags, server=not client_flag or both_flags, both=(client_flag and server_flag) or (not client_flag and not server_flag), - host= get_flag(flags_list, HOST_FLAG, "localhost"), - port= get_flag(flags_list, PORT_FLAG, 8000) + host=get_flag(flags_list, HOST_FLAG, "localhost"), + port=get_flag(flags_list, PORT_FLAG, 8000), ) try: @@ -117,4 +116,4 @@ def _command_line_interface(): except KeyboardInterrupt as e: print("\n\nInterrupt signal received. Shutting down subprocesses...") finally: - close_process() \ No newline at end of file + close_process() diff --git a/src/tqdm_publisher/_demo/_parallel/_client.py b/src/tqdm_publisher/_demo/_parallel/_client.py index 74fd0e0..e6abbee 100644 --- a/src/tqdm_publisher/_demo/_parallel/_client.py +++ b/src/tqdm_publisher/_demo/_parallel/_client.py @@ -3,20 +3,20 @@ # HTTP server addition import http.server import json + +# Kill server on interrupt import signal import socket import socketserver import sys -# Kill server on interrupt -import signal - def find_free_port(): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind(("", 0)) # Bind to a free port provided by the host return s.getsockname()[1] # Return the port number assigned - + + class MyTCPServer(socketserver.TCPServer): allow_reuse_address = True # This allows the server to bind to an address that is in a TIME_WAIT state diff --git a/src/tqdm_publisher/_demo/_parallel/_server.py b/src/tqdm_publisher/_demo/_parallel/_server.py index 7c31687..aca0587 100644 --- a/src/tqdm_publisher/_demo/_parallel/_server.py +++ b/src/tqdm_publisher/_demo/_parallel/_server.py @@ -7,6 +7,7 @@ import uuid from concurrent.futures import ProcessPoolExecutor from typing import Tuple + import requests from tqdm_publisher import TQDMPublisher @@ -76,4 +77,4 @@ def run_demo(host, port): host_index = flags_list.index("--host") HOST = flags_list[host_index + 1] - run_demo(HOST, PORT) \ No newline at end of file + run_demo(HOST, PORT)