Skip to content

Commit 93de0d1

Browse files
committed
Check return codes in mp_run_process
This codepath is not normally used since once currently needs to opt into using via EM_PYTHON_MULTIPROCESSING=1. However, I'm hoping to remove that limitation in #17881. This cleaanup/fix should land before #17881 does. The primary change here is to switch from `subprocessrun.Popen` to `subprocess.run` which supports the `check=True` argument. As well as avoiding the need for the call to `communicate()`
1 parent fdb1656 commit 93de0d1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tools/shared.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,20 @@ def get_num_cores():
116116

117117

118118
def mp_run_process(command_tuple):
119-
temp_files = get_temp_files()
120119
cmd, env, route_stdout_to_temp_files_suffix, pipe_stdout, check, cwd = command_tuple
121-
std_out = temp_files.get(route_stdout_to_temp_files_suffix) if route_stdout_to_temp_files_suffix else (subprocess.PIPE if pipe_stdout else None)
122-
ret = std_out.name if route_stdout_to_temp_files_suffix else None
123-
proc = subprocess.Popen(cmd, stdout=std_out, stderr=subprocess.PIPE if pipe_stdout else None, env=env, cwd=cwd)
124-
out, _ = proc.communicate()
125-
if pipe_stdout:
126-
ret = out.decode('UTF-8')
127-
return ret
120+
stdout = None
121+
stderr = None
122+
if route_stdout_to_temp_files_suffix:
123+
stdout = get_temp_files().get(route_stdout_to_temp_files_suffix)
124+
ret = stdout.name
125+
elif pipe_stdout:
126+
stdout = subprocess.PIPE
127+
stderr = subprocess.PIPE
128+
proc = subprocess.run(cmd, stdout=stdout, stderr=stderr, env=env, cwd=cwd, check=True)
129+
if route_stdout_to_temp_files_suffix:
130+
return stdout.name
131+
elif pipe_stdout:
132+
return proc.stdout.decode('UTF-8')
128133

129134

130135
def returncode_to_str(code):

0 commit comments

Comments
 (0)