Skip to content

Commit 59893b0

Browse files
committed
Add timeout option to run command
1 parent 6c51739 commit 59893b0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/universal_build/build_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,15 @@ def run(
228228
disable_stdout_logging: bool = False,
229229
disable_stderr_logging: bool = False,
230230
exit_on_error: bool = False,
231+
timeout: Optional[int] = None,
231232
) -> subprocess.CompletedProcess:
232-
"""Wrapper for subprocess.run() to print our
233+
"""Run a specified command.
233234
234235
Args:
235236
command (str): The shell command that is executed via subprocess.Popen.
236237
disable_stdout_logging (bool): Disable stdout logging when it is too much or handled by the caller.
238+
exit_on_error (bool): Exit program if the exit code of the command is not 0.
239+
timeout (Optional[int]): Optional timeout for the command.
237240
238241
Returns:
239242
subprocess.CompletedProcess: State
@@ -256,7 +259,8 @@ def run(
256259
log(line.rstrip("\n"))
257260
stderr += line
258261

259-
exitcode = process.wait()
262+
exitcode = process.wait(timeout=timeout)
263+
260264
if exit_on_error and exitcode != 0:
261265
exit_process(exitcode)
262266

0 commit comments

Comments
 (0)