diff --git a/soar_bus.py b/soar_bus.py index 6f5790ba6876b37dd8d46efe2ed2517948042262..aa8fc0054859253232ac53d1f33e0bb25d6661b2 100644 --- a/soar_bus.py +++ b/soar_bus.py @@ -49,7 +49,7 @@ class ConfigHandler(FileSystemEventHandler): def update_clients(updated_client_ids): global RUNNING_CLIENTS - with concurrent.futures.ProcessPoolExecutor() as executor: + with concurrent.futures.ThreadPoolExecutor() as executor: logging.debug("Old: " + str(RUNNING_CLIENTS)) logging.debug("New: " + str(updated_client_ids)) @@ -132,13 +132,10 @@ def run_client(client_id, executor): return running -def main(executor): +def main(clients, executor): global RUNNING_CLIENTS logging.info("Starting SOAR bus...") - client_model = ClientModel() - clients = client_model.get() - # publish thread = executor.submit(publish, "soar-publish", EXCHANGES.get("publish")) THREADS["soar-publish"] = thread @@ -180,7 +177,15 @@ if __name__ == "__main__": s.close() try: - with concurrent.futures.ProcessPoolExecutor() as executor: - main(executor) + client_model = ClientModel() + clients = client_model.get() + client_count = len(clients.keys()) + thread_count = (client_count * 2) + 2 + logging.debug(f"Running {thread_count} workers for {client_count} clients") + + with concurrent.futures.ThreadPoolExecutor( + max_workers=thread_count + ) as executor: + main(clients, executor) except KeyboardInterrupt: executor.shutdown(wait=False)