44import subprocess
55import sys
66from concurrent .futures import Future
7- from typing import Tuple
7+ from typing import Tuple , Optional
88
99from executorlib .standalone .command import get_command_path
1010from executorlib .standalone .hdf import dump , get_output
@@ -48,14 +48,15 @@ def done(self) -> bool:
4848
4949
5050def execute_in_subprocess (
51- command : list , task_dependent_lst : list = []
51+ command : list , task_dependent_lst : list = [], cwd : Optional [ str ] = None ,
5252) -> subprocess .Popen :
5353 """
5454 Execute a command in a subprocess.
5555
5656 Args:
5757 command (list): The command to be executed.
58- task_dependent_lst (list, optional): A list of subprocesses that the current subprocess depends on. Defaults to [].
58+ task_dependent_lst (list): A list of subprocesses that the current subprocess depends on. Defaults to [].
59+ cwd (str/None): current working directory where the parallel python task is executed
5960
6061 Returns:
6162 subprocess.Popen: The subprocess object.
@@ -65,14 +66,15 @@ def execute_in_subprocess(
6566 task_dependent_lst = [
6667 task for task in task_dependent_lst if task .poll () is None
6768 ]
68- return subprocess .Popen (command , universal_newlines = True )
69+ return subprocess .Popen (command , universal_newlines = True , cwd = cwd )
6970
7071
7172def execute_tasks_h5 (
7273 future_queue : queue .Queue ,
7374 cache_directory : str ,
7475 cores_per_worker : int ,
7576 execute_function : callable ,
77+ cwd : Optional [str ],
7678) -> None :
7779 """
7880 Execute tasks stored in a queue using HDF5 files.
@@ -82,6 +84,7 @@ def execute_tasks_h5(
8284 cache_directory (str): The directory to store the HDF5 files.
8385 cores_per_worker (int): The number of cores per worker.
8486 execute_function (callable): The function to execute the tasks.
87+ cwd (str/None): current working directory where the parallel python task is executed
8588
8689 Returns:
8790 None
@@ -123,6 +126,7 @@ def execute_tasks_h5(
123126 task_dependent_lst = [
124127 process_dict [k ] for k in future_wait_key_lst
125128 ],
129+ cwd = cwd ,
126130 )
127131 file_name_dict [task_key ] = os .path .join (
128132 cache_directory , task_key + ".h5out"
0 commit comments