Skip to content

Commit 63422c3

Browse files
fix(tools): add ignore_errors param to execute_command_parallel (#454)
1 parent 4fc87a9 commit 63422c3

5 files changed

Lines changed: 28 additions & 16 deletions

File tree

‎asap-tools/experiments/experiment_utils/providers/base.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def execute_command_parallel(
5656
popen: bool = True,
5757
redirect: bool = False,
5858
wait: bool = True,
59+
ignore_errors: bool = False,
5960
) -> List[subprocess.Popen]:
6061
"""
6162
Execute a command on multiple nodes in parallel.
@@ -68,6 +69,7 @@ def execute_command_parallel(
6869
popen: Must be True for parallel execution
6970
redirect: Whether to redirect output to /dev/null
7071
wait: Whether to wait for all commands to complete
72+
ignore_errors: Whether to ignore command execution errors
7173
7274
Returns:
7375
List of Popen objects for each node

‎asap-tools/experiments/experiment_utils/providers/cloudlab.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def execute_command_parallel(
7878
popen: bool = True,
7979
redirect: bool = False,
8080
wait: bool = True,
81+
ignore_errors: bool = False,
8182
) -> List[subprocess.Popen]:
8283
"""
8384
Execute a command on multiple CloudLab nodes in parallel via SSH.

‎asap-tools/experiments/experiment_utils/providers/cloudlab_local.py‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,20 @@ def execute_command(
8181

8282
# Execute locally
8383
if popen:
84-
return subprocess.Popen(
85-
cmd,
86-
shell=True,
87-
cwd=cmd_dir,
88-
stdout=subprocess.PIPE,
89-
stderr=subprocess.PIPE,
90-
text=True,
91-
)
84+
try:
85+
return subprocess.Popen(
86+
cmd,
87+
shell=True,
88+
cwd=cmd_dir,
89+
stdout=subprocess.PIPE,
90+
stderr=subprocess.PIPE,
91+
text=True,
92+
)
93+
except OSError as e:
94+
if ignore_errors:
95+
print(f"Warning: failed to launch '{cmd}' in {cmd_dir!r}: {e}")
96+
return None
97+
raise
9298
else:
9399
try:
94100
result = subprocess.run(
@@ -100,7 +106,7 @@ def execute_command(
100106
check=not ignore_errors,
101107
)
102108
return result
103-
except subprocess.CalledProcessError as e:
109+
except (subprocess.CalledProcessError, OSError) as e:
104110
if ignore_errors:
105111
return e
106112
raise
@@ -114,6 +120,7 @@ def execute_command_parallel(
114120
popen: bool = True,
115121
redirect: bool = False,
116122
wait: bool = True,
123+
ignore_errors: bool = False,
117124
) -> List[subprocess.Popen]:
118125
"""
119126
Execute a command in parallel locally.
@@ -129,6 +136,7 @@ def execute_command_parallel(
129136
popen: Must be True for parallel execution
130137
redirect: Whether to redirect output to /dev/null
131138
wait: Whether to wait for all commands to complete
139+
ignore_errors: Whether to ignore command execution errors
132140
133141
Returns:
134142
List containing single Popen object
@@ -144,6 +152,7 @@ def execute_command_parallel(
144152
cmd_dir=cmd_dir,
145153
nohup=nohup,
146154
popen=True, # Always return Popen for parallel
155+
ignore_errors=ignore_errors,
147156
)
148157

149158
processes = [process]

‎asap-tools/experiments/experiment_utils/providers/local.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ def execute_command(
6464
text=True,
6565
)
6666
except OSError as e:
67-
# execute_command_parallel has no ignore_errors knob (see
68-
# follow-up issue), so this can't be conditional yet. Mirrors
69-
# CloudLab's SSH transport: launching `ssh` locally never
70-
# fails even if the remote cmd_dir is missing — the failure
71-
# is invisible unless something later checks output/health.
72-
print(f"Warning: failed to launch '{cmd}' in {cmd_dir!r}: {e}")
73-
return None
67+
if ignore_errors:
68+
print(f"Warning: failed to launch '{cmd}' in {cmd_dir!r}: {e}")
69+
return None
70+
raise
7471

7572
try:
7673
return subprocess.run(
@@ -101,6 +98,7 @@ def execute_command_parallel(
10198
popen: bool = True,
10299
redirect: bool = False,
103100
wait: bool = True,
101+
ignore_errors: bool = False,
104102
) -> List[subprocess.Popen]:
105103
"""Execute a command once locally (there is only one local node)."""
106104
if redirect:
@@ -112,6 +110,7 @@ def execute_command_parallel(
112110
cmd_dir=cmd_dir,
113111
nohup=nohup,
114112
popen=True,
113+
ignore_errors=ignore_errors,
115114
)
116115
processes = [process]
117116
if wait:

‎asap-tools/experiments/experiment_utils/services/misc.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def stop(self, **kwargs) -> None:
7979
nohup=False,
8080
popen=True,
8181
wait=True,
82+
ignore_errors=True,
8283
)
8384

8485
def run_workload(

0 commit comments

Comments
 (0)