File tree 3 files changed +15
-10
lines changed
3 files changed +15
-10
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 ()
Original file line number Diff line number Diff line change 10
10
def create_large_file (tmp_path ):
11
11
def _create_large_file (extension ):
12
12
path = tmp_path / f"large{ extension } "
13
- random_text = "" .join (random .choices (string .ascii_lowercase , k = 1024 ))
14
- # Make the text a lot bigger in order to ensure that it is larger than the
15
- # pipe buffer size.
16
- random_text *= 2048
13
+ random .seed (0 )
14
+ chars = string .ascii_lowercase + "\n "
15
+ # Do not decrease this length. The generated file needs to have
16
+ # a certain length after compression to trigger some bugs
17
+ # (in particular, 512 kB is not sufficient).
18
+ random_text = "" .join (random .choices (chars , k = 1024 * 1024 ))
17
19
with xopen (path , "w" ) as f :
18
20
f .write (random_text )
19
21
return path
Original file line number Diff line number Diff line change 6
6
import os
7
7
import shutil
8
8
import sys
9
- import time
10
9
import pytest
11
10
from pathlib import Path
12
11
from itertools import cycle
@@ -189,8 +188,6 @@ def test_reader_close(reader, create_large_file):
189
188
large_file , "rb" , program_settings = program_settings
190
189
) as f :
191
190
f .readline ()
192
- time .sleep (0.2 )
193
- # The subprocess should be properly terminated now
194
191
195
192
196
193
def test_invalid_gzip_compression_level (gzip_writer , tmp_path ):
You can’t perform that action at this time.
0 commit comments