forked from clan/clan-core
Merge pull request 'cmd: add a timeout in select' (#716) from Mic92-HEAD into main
This commit is contained in:
commit
1cdc2b8ed2
@ -26,10 +26,13 @@ def handle_output(process: subprocess.Popen, log: Log) -> tuple[str, str]:
|
|||||||
stdout_buf = b""
|
stdout_buf = b""
|
||||||
stderr_buf = b""
|
stderr_buf = b""
|
||||||
|
|
||||||
while process.poll() is None:
|
while len(rlist) != 0:
|
||||||
if len(rlist) == 0:
|
r, _, _ = select.select(rlist, [], [], 0.1)
|
||||||
|
if len(r) == 0: # timeout in select
|
||||||
|
if process.poll() is None:
|
||||||
|
continue
|
||||||
|
# Process has exited
|
||||||
break
|
break
|
||||||
r, _, _ = select.select(rlist, [], [], 0)
|
|
||||||
|
|
||||||
def handle_fd(fd: IO[Any] | None) -> bytes:
|
def handle_fd(fd: IO[Any] | None) -> bytes:
|
||||||
if fd and fd in r:
|
if fd and fd in r:
|
||||||
@ -71,13 +74,12 @@ def run(
|
|||||||
env=env,
|
env=env,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
stdout_buf, stderr_buf = handle_output(process, log)
|
stdout_buf, stderr_buf = handle_output(process, log)
|
||||||
|
|
||||||
# Wait for the subprocess to finish
|
|
||||||
rc = process.wait()
|
rc = process.wait()
|
||||||
|
|
||||||
|
# Wait for the subprocess to finish
|
||||||
cmd_out = CmdOut(
|
cmd_out = CmdOut(
|
||||||
stdout=stdout_buf,
|
stdout=stdout_buf,
|
||||||
stderr=stderr_buf,
|
stderr=stderr_buf,
|
||||||
|
Loading…
Reference in New Issue
Block a user