@@ -32,8 +32,9 @@ def run_multiple_commands(
3232 Executes multiple shell commands concurrently in separate threads.
3333
3434 This method leverages threading to run each command in parallel, improving
35- efficiency for batch command execution. Execution time and command results are
36- logged if specified.
35+ efficiency for batch command execution. The number of concurrent commands
36+ is limited by the max_threads setting, which is distributed between
37+ parallel command execution and per-tool thread allocation.
3738
3839 Args:
3940 commands (list[str]): A list where each element is a list representing
@@ -42,17 +43,26 @@ def run_multiple_commands(
4243 Returns:
4344 bool: True if all commands succeeded, False if any failed.
4445 """
46+ from src .common .common import get_max_threads
47+
48+ # Get thread settings and calculate distribution
49+ max_threads = get_max_threads ()
50+ num_commands = len (commands )
51+ parallel_commands = min (num_commands , max_threads )
52+
4553 # Log the start of command execution
46- self .logger .log (f"Running { len ( commands ) } commands in parallel..." , 1 )
54+ self .logger .log (f"Running { num_commands } commands (max { parallel_commands } parallel, { max_threads } total threads) ..." , 1 )
4755 start_time = time .time ()
4856
4957 results = []
5058 lock = threading .Lock ()
59+ semaphore = threading .Semaphore (parallel_commands )
5160
5261 def run_and_track (cmd ):
53- success = self .run_command (cmd )
54- with lock :
55- results .append (success )
62+ with semaphore :
63+ success = self .run_command (cmd )
64+ with lock :
65+ results .append (success )
5666
5767 # Initialize a list to keep track of threads
5868 threads = []
@@ -69,7 +79,7 @@ def run_and_track(cmd):
6979
7080 # Calculate and log the total execution time
7181 end_time = time .time ()
72- self .logger .log (f"Total time to run { len ( commands ) } commands: { end_time - start_time :.2f} seconds" , 1 )
82+ self .logger .log (f"Total time to run { num_commands } commands: { end_time - start_time :.2f} seconds" , 1 )
7383
7484 return all (results )
7585
@@ -210,6 +220,12 @@ def run_topp(self, tool: str, input_output: dict, custom_params: dict = {}) -> b
210220 else :
211221 n_processes = max (io_lengths )
212222
223+ # Calculate threads per command based on max_threads setting
224+ from src .common .common import get_max_threads
225+ max_threads = get_max_threads ()
226+ parallel_commands = min (n_processes , max_threads )
227+ threads_per_command = max (1 , max_threads // parallel_commands )
228+
213229 commands = []
214230
215231 # Load parameters for non-defaults
@@ -253,6 +269,8 @@ def run_topp(self, tool: str, input_output: dict, custom_params: dict = {}) -> b
253269 command += [str (x ) for x in v ]
254270 else :
255271 command += [str (v )]
272+ # Add threads parameter for TOPP tools
273+ command += ["-threads" , str (threads_per_command )]
256274 commands .append (command )
257275
258276 # check if a ini file has been written, if yes use it (contains custom defaults)
0 commit comments