Skip to content

Commit

Permalink
remove stdout=subprocess.PIPE from env._call, which can cause poetry …
Browse files Browse the repository at this point in the history
…install to hang (#7699)

Co-authored-by: Randy Döring <[email protected]>
(cherry picked from commit fa5543a)
  • Loading branch information
fzahle authored and github-actions[bot] committed Mar 23, 2023
1 parent 84cc8b1 commit bfc6295
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
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

0 comments on commit bfc6295

Please sign in to comment.