@@ -107,40 +107,42 @@ def batch_run(
107
107
for i in range (0 , len (images ), batchsize )
108
108
]
109
109
110
- process = subprocess .Popen (
111
- [* args , * map (str , images ), * post_args ],
112
- stdout = subprocess .PIPE ,
113
- stderr = subprocess .PIPE ,
114
- ** kwargs ,
115
- )
116
-
117
110
if stdout_write is None :
118
111
stdout_write = partial (print , file = sys .stdout )
119
112
if stderr_write is None :
120
113
stderr_write = partial (print , file = sys .stderr )
121
114
122
- stdout_thread = threading .Thread (
123
- target = forward_output , args = (process .stdout , stdout_write , trim_printout )
124
- )
125
- stderr_thread = threading .Thread (
126
- target = forward_output , args = (process .stderr , stderr_write , trim_printout )
127
- )
115
+ try :
116
+ process = subprocess .Popen (
117
+ [* args , * map (str , images ), * post_args ],
118
+ stdout = subprocess .PIPE ,
119
+ stderr = subprocess .PIPE ,
120
+ ** kwargs ,
121
+ )
122
+
123
+ stdout_thread = threading .Thread (
124
+ target = forward_output , args = (process .stdout , stdout_write , trim_printout )
125
+ )
126
+ stderr_thread = threading .Thread (
127
+ target = forward_output , args = (process .stderr , stderr_write , trim_printout )
128
+ )
128
129
129
- stdout_thread .start ()
130
- stderr_thread .start ()
130
+ stdout_thread .start ()
131
+ stderr_thread .start ()
131
132
132
- stdout_thread .join ()
133
- stderr_thread .join ()
133
+ stdout_thread .join ()
134
+ stderr_thread .join ()
134
135
135
- process .wait ()
136
+ process .wait ()
136
137
137
- if check and process .returncode != 0 :
138
- exn = subprocess .CalledProcessError (process .returncode , process .args )
138
+ if check and process .returncode != 0 :
139
+ raise subprocess .CalledProcessError (process .returncode , process .args )
140
+ except (FileNotFoundError , subprocess .CalledProcessError , OSError ) as e :
139
141
if wrap_errs is not None :
140
- stderr_write (f"Error: { exn } " )
141
- wrap_errs .append (exn )
142
+ stderr_write (f"Error: { e } " )
143
+ wrap_errs .append (e )
142
144
else :
143
- raise exn
145
+ raise e
144
146
145
147
return process
146
148
0 commit comments