From 50c4c53d579dd365183f22b925e77b971213b525 Mon Sep 17 00:00:00 2001 From: frza Date: Wed, 22 Mar 2023 00:13:23 +0100 Subject: [PATCH 1/3] remove stdout=subprocess.PIPE from env._call, see #7698 --- src/poetry/utils/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index d5755d152c3..050db2c447a 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1538,7 +1538,7 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str: ).stdout elif call: return subprocess.call( - cmd, stdout=subprocess.PIPE, stderr=stderr, env=env, **kwargs + cmd, stderr=stderr, env=env, **kwargs ) else: output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs) From 16e8f4ba3edf22912261c8dc59d6fcfef8166fd9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Mar 2023 23:30:58 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/poetry/utils/env.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 050db2c447a..f48ffdf07e3 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1537,9 +1537,7 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str: **kwargs, ).stdout elif call: - return subprocess.call( - cmd, stderr=stderr, env=env, **kwargs - ) + return subprocess.call(cmd, stderr=stderr, env=env, **kwargs) else: output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs) except CalledProcessError as e: From 2a952ffc4b3d576d46f5bc62b12d091a803ddc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Wed, 22 Mar 2023 18:18:37 +0100 Subject: [PATCH 3/3] add test --- src/poetry/utils/env.py | 1 + tests/utils/test_env.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index f48ffdf07e3..aa4d58bf223 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1537,6 +1537,7 @@ def _run(self, cmd: list[str], **kwargs: Any) -> int | str: **kwargs, ).stdout elif call: + assert stderr != subprocess.PIPE return subprocess.call(cmd, stderr=stderr, env=env, **kwargs) else: output = subprocess.check_output(cmd, stderr=stderr, env=env, **kwargs) diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index eb7b2ec59eb..07823d4fb55 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -5,6 +5,7 @@ import sys from pathlib import Path +from threading import Thread from typing import TYPE_CHECKING from typing import Any @@ -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 ):