Skip to content

Commit 5955c6a

Browse files
fzahleradoering
andcommitted
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> (cherry picked from commit fa5543a)
1 parent 84cc8b1 commit 5955c6a

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/poetry/utils/env.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,9 +1537,8 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
15371537
**kwargs,
15381538
).stdout
15391539
elif call:
1540-
return subprocess.call(
1541-
cmd, stdout=subprocess.PIPE, stderr=stderr, env=env, **kwargs
1542-
)
1540+
assert stderr != subprocess.PIPE
1541+
return subprocess.call(cmd, stderr=stderr, env=env, **kwargs)
15431542
else:
15441543
output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs)
15451544
except CalledProcessError as e:

tests/utils/test_env.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66

77
from pathlib import Path
8+
from threading import Thread
89
from typing import TYPE_CHECKING
910
from typing import Any
1011

@@ -1009,6 +1010,31 @@ def test_check_output_with_called_process_error(
10091010
assert "some error" in str(error.value)
10101011

10111012

1013+
@pytest.mark.parametrize("out", ["sys.stdout", "sys.stderr"])
1014+
def test_call_does_not_block_on_full_pipe(
1015+
tmp_path: Path, tmp_venv: VirtualEnv, out: str
1016+
):
1017+
"""see https://github.com/python-poetry/poetry/issues/7698"""
1018+
script = tmp_path / "script.py"
1019+
script.write_text(
1020+
f"""\
1021+
import sys
1022+
for i in range(10000):
1023+
print('just print a lot of text to fill the buffer', file={out})
1024+
"""
1025+
)
1026+
1027+
def target(result: list[int]) -> None:
1028+
result.append(tmp_venv.run("python", str(script), call=True))
1029+
1030+
results = []
1031+
# use a separate thread, so that the test does not block in case of error
1032+
thread = Thread(target=target, args=(results,))
1033+
thread.start()
1034+
thread.join(1) # must not block
1035+
assert results and results[0] == 0
1036+
1037+
10121038
def test_run_python_script_called_process_error(
10131039
tmp_dir: str, tmp_venv: VirtualEnv, mocker: MockerFixture
10141040
):

0 commit comments

Comments
 (0)