Commit 808e48be authored by Dan Jones's avatar Dan Jones
Browse files

Merge branch '40-use-threadpoolexecutor-in-place-of-processpoolexecutor' into 'dev'

Resolve "Use ThreadPoolExecutor in place of ProcessPoolExecutor"

Closes #40

See merge request !20
parents 56dd8725 204bb35a
2 merge requests!23Resolve "Release v0.1.0",!20Resolve "Use ThreadPoolExecutor in place of ProcessPoolExecutor"
Pipeline #110248 passed with stages
in 1 minute and 1 second
......@@ -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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment