Skip to content

Commit 5776926

Browse files
committed
connectors: close stdin after writing any input
Turns out some applications will wait on stdin being closed before going anything (ollama), see: #1355
1 parent e8c31d3 commit 5776926

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/pyinfra/connectors/ssh.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,10 @@ def execute_command() -> Tuple[int, CommandOutput]:
397397
get_pty=_get_pty,
398398
)
399399

400+
# Write any stdin and then close it
400401
if _stdin:
401402
write_stdin(_stdin, stdin_buffer)
403+
stdin_buffer.close()
402404

403405
combined_output = read_output_buffers(
404406
stdout_buffer,

src/pyinfra/connectors/util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ def run_local_process(
4444
) -> tuple[int, "CommandOutput"]:
4545
process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
4646

47-
if stdin:
48-
write_stdin(stdin, process.stdin)
49-
5047
assert process.stdout is not None
5148
assert process.stderr is not None
49+
assert process.stdin is not None
50+
51+
# Write any stdin and then close it
52+
if stdin:
53+
write_stdin(stdin, process.stdin)
54+
process.stdin.close()
5255

5356
combined_output = read_output_buffers(
5457
process.stdout,

0 commit comments

Comments
 (0)