pyinfra
pyinfra copied to clipboard
Possible issue with timeout in read_output_buffers
Describe the bug
I'm not sure if timeout should be optional (per the functions interface) or mandatory but when i try to call it without timeout I see TypeError.
def read_output_buffers(
stdout_buffer: Iterable,
stderr_buffer: Iterable,
timeout: Optional[int],
print_output: bool,
print_prefix: str,
) -> CommandOutput:
output_queue: Queue[OutputLine] = Queue()
...
# Wait on output, with our timeout (or None)
greenlets = gevent.wait((stdout_reader, stderr_reader), timeout=timeout)
To Reproduce
Within run_shell_command in my connector I have the following block:
status, stdout, stderr = self.lxd_api_client.execute_command(instance_name=api_name, commands=commands_to_run)
logger.debug('{} run completed, status {}'.format(host.name, status))
# TODO: set stderr/stdout to None if they are zero length? will that stop unnecessary blank lines in output?
# Use read_output_buffers to process stdout/err into the format expected by the calling code within pyinfra
# Provided output streams need to be supplied as lists.
combined_output = read_output_buffers(
[stdout],
[stderr],
# read_output_buffers definition says this is optional but it appears to be required within the function
timeout=15,
print_output=True,
print_prefix=api_name,
)
When run I have the following error:
File "/home/kgoetz/source/pyinfra_lxc/pyinfra_lxc/connectors.py", line 193, in run_shell_command
combined_output = read_output_buffers(
^^^^^^^^^^^^^^^^^^^^
TypeError: read_output_buffers() missing 1 required positional argument: 'timeout'
Expected behavior
timeout optional/has default setting.
Meta
(pyinfra) kgoetz@L23001:~/source/pyinfra_tests$ pyinfra --support
If you are having issues with pyinfra or wish to make feature requests, please
check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
When adding an issue, be sure to include the following:
System: Linux
Platform: Linux-6.1.0-31-amd64-x86_64-with-glibc2.36
Release: 6.1.0-31-amd64
Machine: x86_64
pyinfra: v3.2
click: v8.1.8
coverage: v7.6.12
coverage: v7.6.12
distro: v1.9.0
gevent: v24.11.1
jinja2: v3.1.5
packaging: v24.2
paramiko: v3.5.1
pytest: v8.3.4
pytest: v8.3.4
pytest-cov: v6.0.0
pytest-cov: v6.0.0
python-dateutil: v2.9.0.post0
pywinrm: v0.5.0
setuptools: v66.1.1
typeguard: v4.4.1
typing-extensions: v4.12.2
wheel: v0.38.4
Executable: /home/kgoetz/.venvs/pyinfra/bin/pyinfra
Python: 3.11.2 (CPython, GCC 12.2.0)
(pyinfra) kgoetz@L23001:~/source/pyinfra_tests$ pip list |grep pyin
pyinfra 3.2
pyinfra_lxc 0.0.1 /home/kgoetz/source/pyinfra_lxc
(pyinfra) kgoetz@L23001:~/source/pyinfra_tests$