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
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): ...@@ -49,7 +49,7 @@ class ConfigHandler(FileSystemEventHandler):
def update_clients(updated_client_ids): def update_clients(updated_client_ids):
global RUNNING_CLIENTS global RUNNING_CLIENTS
with concurrent.futures.ProcessPoolExecutor() as executor: with concurrent.futures.ThreadPoolExecutor() as executor:
logging.debug("Old: " + str(RUNNING_CLIENTS)) logging.debug("Old: " + str(RUNNING_CLIENTS))
logging.debug("New: " + str(updated_client_ids)) logging.debug("New: " + str(updated_client_ids))
...@@ -132,13 +132,10 @@ def run_client(client_id, executor): ...@@ -132,13 +132,10 @@ def run_client(client_id, executor):
return running return running
def main(executor): def main(clients, executor):
global RUNNING_CLIENTS global RUNNING_CLIENTS
logging.info("Starting SOAR bus...") logging.info("Starting SOAR bus...")
client_model = ClientModel()
clients = client_model.get()
# publish # publish
thread = executor.submit(publish, "soar-publish", EXCHANGES.get("publish")) thread = executor.submit(publish, "soar-publish", EXCHANGES.get("publish"))
THREADS["soar-publish"] = thread THREADS["soar-publish"] = thread
...@@ -180,7 +177,15 @@ if __name__ == "__main__": ...@@ -180,7 +177,15 @@ if __name__ == "__main__":
s.close() s.close()
try: try:
with concurrent.futures.ProcessPoolExecutor() as executor: client_model = ClientModel()
main(executor) 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: except KeyboardInterrupt:
executor.shutdown(wait=False) 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