File tree Expand file tree Collapse file tree 1 file changed +19
-29
lines changed Expand file tree Collapse file tree 1 file changed +19
-29
lines changed Original file line number Diff line number Diff line change 21
21
import tempfile
22
22
import threading
23
23
import time
24
- from subprocess import Popen , PIPE
25
24
from typing import (
26
25
Dict ,
27
26
Optional ,
@@ -230,41 +229,32 @@ def __init__( # noqa: C901
230
229
self ._feeding = True
231
230
if "r" in mode :
232
231
self ._program_args += ["-c" , "-d" ] # type: ignore
233
- try :
234
- self .process = subprocess .Popen (
235
- self ._program_args ,
236
- stderr = self ._stderr ,
237
- stdout = PIPE ,
238
- stdin = PIPE ,
239
- close_fds = close_fds ,
240
- ) # type: ignore
241
- except OSError :
242
- if self .closefd :
243
- self .fileobj .close ()
244
- raise
245
- assert self .process .stdin is not None
232
+ stdout = subprocess .PIPE
233
+ else :
234
+ if compresslevel is not None :
235
+ self ._program_args += ["-" + str (compresslevel )]
236
+ stdout = self .fileobj # type: ignore
237
+ try :
238
+ self .process = subprocess .Popen (
239
+ self ._program_args ,
240
+ stderr = self ._stderr ,
241
+ stdout = stdout ,
242
+ stdin = subprocess .PIPE ,
243
+ close_fds = close_fds ,
244
+ ) # type: ignore
245
+ except OSError :
246
+ if self .closefd :
247
+ self .fileobj .close ()
248
+ raise
249
+ assert self .process .stdin is not None
250
+ if "r" in mode :
246
251
self .in_pipe = self .process .stdin
247
252
self .in_thread = threading .Thread (target = self ._feed_pipe )
248
253
self .in_thread .start ()
249
254
self ._file : BinaryIO = self .process .stdout # type: ignore
250
255
self ._wait_for_output_or_process_exit ()
251
256
self ._raise_if_error ()
252
257
else :
253
- if compresslevel is not None :
254
- self ._program_args += ["-" + str (compresslevel )]
255
- try :
256
- self .process = Popen (
257
- self ._program_args ,
258
- stderr = self ._stderr ,
259
- stdin = PIPE ,
260
- stdout = self .fileobj ,
261
- close_fds = close_fds ,
262
- ) # type: ignore
263
- except OSError :
264
- if self .closefd :
265
- self .fileobj .close ()
266
- raise
267
- assert self .process .stdin is not None
268
258
self ._file = self .process .stdin # type: ignore
269
259
270
260
_set_pipe_size_to_max (self ._file .fileno ())
You can’t perform that action at this time.
0 commit comments