Skip to content

Commit 5d49743

Browse files
committed
Fix for run multiple commands
1 parent 30d746f commit 5d49743

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/workflow/CommandExecutor.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import importlib.util
1111
import json
12+
import queue
1213

1314
class CommandExecutor:
1415
"""
@@ -43,12 +44,21 @@ def run_multiple_commands(
4344
self.logger.log(f"Running {len(commands)} commands in parallel...", 1)
4445
start_time = time.time()
4546

47+
# Queue to capture exceptions from threads
48+
exceptions_queue = queue.Queue()
49+
50+
def run_command_thread_target(cmd):
51+
try:
52+
self.run_command(cmd)
53+
except Exception as e:
54+
exceptions_queue.put(e)
55+
4656
# Initialize a list to keep track of threads
4757
threads = []
4858

4959
# Start a new thread for each command
5060
for cmd in commands:
51-
thread = threading.Thread(target=self.run_command, args=(cmd,))
61+
thread = threading.Thread(target=run_command_thread_target, args=(cmd,))
5262
thread.start()
5363
threads.append(thread)
5464

@@ -60,6 +70,11 @@ def run_multiple_commands(
6070
end_time = time.time()
6171
self.logger.log(f"Total time to run {len(commands)} commands: {end_time - start_time:.2f} seconds", 1)
6272

73+
# Exceptions are logged once all threads have completed execution
74+
# The first exception amongst all is logged and raised
75+
if not exceptions_queue.empty():
76+
raise RuntimeError(exceptions_queue.get())
77+
6378
def run_command(self, command: list[str]) -> None:
6479
"""
6580
Executes a specified shell command and logs its execution details.

0 commit comments

Comments
 (0)