Commit fa5543a6 by Frederik Zahle Committed by GitHub

remove stdout=subprocess.PIPE from env._call, which can cause poetry install to hang (#7699)

Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
parent 71b3d6e0
...@@ -1537,9 +1537,8 @@ class Env: ...@@ -1537,9 +1537,8 @@ class Env:
**kwargs, **kwargs,
).stdout ).stdout
elif call: elif call:
return subprocess.call( assert stderr != subprocess.PIPE
cmd, stdout=subprocess.PIPE, stderr=stderr, env=env, **kwargs return subprocess.call(cmd, stderr=stderr, env=env, **kwargs)
)
else: else:
output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs) output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs)
except CalledProcessError as e: except CalledProcessError as e:
......
...@@ -5,6 +5,7 @@ import subprocess ...@@ -5,6 +5,7 @@ import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
from threading import Thread
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any from typing import Any
...@@ -1009,6 +1010,31 @@ def test_check_output_with_called_process_error( ...@@ -1009,6 +1010,31 @@ def test_check_output_with_called_process_error(
assert "some error" in str(error.value) assert "some error" in str(error.value)
@pytest.mark.parametrize("out", ["sys.stdout", "sys.stderr"])
def test_call_does_not_block_on_full_pipe(
tmp_path: Path, tmp_venv: VirtualEnv, out: str
):
"""see https://github.com/python-poetry/poetry/issues/7698"""
script = tmp_path / "script.py"
script.write_text(
f"""\
import sys
for i in range(10000):
print('just print a lot of text to fill the buffer', file={out})
"""
)
def target(result: list[int]) -> None:
result.append(tmp_venv.run("python", str(script), call=True))
results = []
# use a separate thread, so that the test does not block in case of error
thread = Thread(target=target, args=(results,))
thread.start()
thread.join(1) # must not block
assert results and results[0] == 0
def test_run_python_script_called_process_error( def test_run_python_script_called_process_error(
tmp_dir: str, tmp_venv: VirtualEnv, mocker: MockerFixture tmp_dir: str, tmp_venv: VirtualEnv, mocker: MockerFixture
): ):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment