Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,9 +1537,8 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str:
**kwargs,
).stdout
elif call:
return subprocess.call(
cmd, stdout=subprocess.PIPE, stderr=stderr, env=env, **kwargs
)
assert stderr != subprocess.PIPE
return subprocess.call(cmd, stderr=stderr, env=env, **kwargs)
else:
output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs)
except CalledProcessError as e:
Expand Down
26 changes: 26 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from pathlib import Path
from threading import Thread
from typing import TYPE_CHECKING
from typing import Any

Expand Down Expand Up @@ -1009,6 +1010,31 @@ def test_check_output_with_called_process_error(
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(
tmp_dir: str, tmp_venv: VirtualEnv, mocker: MockerFixture
):
Expand Down