Skip to content

Commit a1286cf

Browse files
committed
Reproduce blocking threads issue
1 parent 4229fc7 commit a1286cf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_igzip_threaded.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import io
1010
import itertools
1111
import os
12+
import subprocess
13+
import sys
1214
import tempfile
1315
from pathlib import Path
1416

@@ -218,3 +220,22 @@ def test_threaded_writer_does_not_close_stream():
218220
assert not test_stream.closed
219221
test_stream.seek(0)
220222
assert gzip.decompress(test_stream.read()) == b"thisisatest"
223+
224+
225+
@pytest.mark.timeout(5)
226+
@pytest.mark.parametrize(
227+
["mode", "threads"], itertools.product(["rb", "wb"], [1, 2]))
228+
def test_threaded_program_can_exit_on_error(tmp_path, mode, threads):
229+
program = tmp_path / "no_context_manager.py"
230+
test_file = tmp_path / "output.gz"
231+
# Write 40 mb input data to saturate read buffer. Because of the repetitive
232+
# nature the resulting gzip file is very small (~40 KiB).
233+
test_file.write_bytes(gzip.compress(b"test" * (10 * 1024 * 1024)))
234+
with open(program, "wt") as f:
235+
f.write("from isal import igzip_threaded\n")
236+
f.write(
237+
f"f = igzip_threaded.open('{test_file}', "
238+
f"mode='{mode}', threads={threads})\n"
239+
)
240+
f.write("raise Exception('Error')\n")
241+
subprocess.run([sys.executable, str(program)])

0 commit comments

Comments
 (0)