File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,7 @@ def _open_process(self):
267
267
# data continuously to the process stdin on another thread.
268
268
self .in_thread = threading .Thread (target = self ._feed_pipe )
269
269
self .in_thread .start ()
270
+ self ._process_explicitly_terminated = False
270
271
self ._file : BinaryIO = self .process .stdout # type: ignore
271
272
self ._wait_for_output_or_process_exit ()
272
273
self ._raise_if_error ()
@@ -290,7 +291,11 @@ def _feed_pipe(self):
290
291
if chunk == b"" :
291
292
self .in_pipe .close ()
292
293
return
293
- self .in_pipe .write (chunk )
294
+ try :
295
+ self .in_pipe .write (chunk )
296
+ except BrokenPipeError :
297
+ if not self ._process_explicitly_terminated :
298
+ raise
294
299
finally :
295
300
self .in_pipe .close ()
296
301
@@ -329,14 +334,15 @@ def close(self) -> None:
329
334
return
330
335
check_allowed_code_and_message = False
331
336
if "r" in self ._mode :
332
- self ._feeding = False
333
- self ._file .read ()
334
337
retcode = self .process .poll ()
335
338
if retcode is None :
336
339
# still running
340
+ self ._process_explicitly_terminated = True
337
341
self .process .terminate ()
338
342
check_allowed_code_and_message = True
339
343
self .process .wait ()
344
+ self ._feeding = False
345
+ self ._file .read ()
340
346
if self .in_thread :
341
347
self .in_thread .join ()
342
348
self ._file .close ()
You can’t perform that action at this time.
0 commit comments