From 868f9f9df8b30872e60047f665c269710629a87e Mon Sep 17 00:00:00 2001 From: Tony Ngumah Date: Thu, 12 Dec 2024 16:07:15 -0500 Subject: [PATCH] Changes process calls to speed up code execution --- abr-testing/abr_testing/tools/make_push.py | 46 ++++++++++------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/abr-testing/abr_testing/tools/make_push.py b/abr-testing/abr_testing/tools/make_push.py index 28a69b11103..665831158bc 100644 --- a/abr-testing/abr_testing/tools/make_push.py +++ b/abr-testing/abr_testing/tools/make_push.py @@ -1,7 +1,8 @@ """Push one or more folders to one or more robots.""" import subprocess -import multiprocessing import json +from typing import List +from multiprocessing import Process, Queue global folders # Opentrons folders that can be pushed to robot @@ -13,13 +14,13 @@ ] -def push_subroutine(cmd: str) -> None: +def push_subroutine(cmd: str, queue: Queue) -> None: """Pushes specified folder to specified robot.""" try: subprocess.run(cmd) + queue.put(f"{cmd}: SUCCESS!\n") except Exception: - print("failed to push folder") - raise + queue.put(f"{cmd}: FAILED\n") def main(folder_to_push: str, robot_to_push: str) -> int: @@ -27,6 +28,8 @@ def main(folder_to_push: str, robot_to_push: str) -> int: cmd = "make -C {folder} push-ot3 host={ip}" robot_ip_path = "" push_cmd = "" + processes: List[Process] = [] + queue: Queue = Queue() folder_int = int(folder_to_push) if folders[folder_int].lower() == "abr-testing + hardware-testing": if robot_to_push.lower() == "all": @@ -41,20 +44,16 @@ def main(folder_to_push: str, robot_to_push: str) -> int: for folder_name in folders[:-2]: # Push abr-testing and hardware-testing folders to all robots for robot in robot_ips: - print_proc = multiprocessing.Process( - target=print, args=(f"Pushing {folder_name} to {robot}!\n\n",) - ) - print_proc.start() - print_proc.join() push_cmd = cmd.format(folder=folder_name, ip=robot) - process = multiprocessing.Process( - target=push_subroutine, args=(push_cmd,) + process = Process( + target=push_subroutine, + args=( + push_cmd, + queue, + ), ) process.start() - process.join() - print_proc = multiprocessing.Process(target=print, args=("Done!\n\n",)) - print_proc.start() - print_proc.join() + processes.append(process) else: if folder_int == (len(folders) - 1): @@ -72,18 +71,15 @@ def main(folder_to_push: str, robot_to_push: str) -> int: # Push folder to robots for robot in robot_ips: - print_proc = multiprocessing.Process( - target=print, args=(f"Pushing {folder_name} to {robot}!\n\n",) - ) - print_proc.start() - print_proc.join() push_cmd = cmd.format(folder=folder_name, ip=robot) - process = multiprocessing.Process(target=push_subroutine, args=(push_cmd,)) + process = Process(target=push_subroutine, args=(push_cmd, queue)) process.start() - process.join() - print_proc = multiprocessing.Process(target=print, args=("Done!\n\n",)) - print_proc.start() - print_proc.join() + processes.append(process) + + for process in processes: + process.join() + result = queue.get() + print(f"\n{result}") return 0