Skip to content

Commit

Permalink
shellutils: added a parameter to timeout command
Browse files Browse the repository at this point in the history
* Added an option to run_process_with_timeout() to specify if
  the command should be called through the shell or not.
  • Loading branch information
jalavik authored and tiborsimko committed Dec 6, 2010
1 parent 84f6dc4 commit 35938ec
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modules/miscutil/lib/shellutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def run_shell_command(cmd, args=None, filename_out=None, filename_err=None):
# return results:
return cmd_exit_code, cmd_out, cmd_err

def run_process_with_timeout(args, filename_in=None, filename_out=None, filename_err=None, cwd=None, timeout=CFG_MISCUTIL_DEFAULT_PROCESS_TIMEOUT):
def run_process_with_timeout(args, filename_in=None, filename_out=None, filename_err=None, cwd=None, timeout=CFG_MISCUTIL_DEFAULT_PROCESS_TIMEOUT, shell=False):
"""
Run a process capturing its output and killing it after a given timeout.
Expand All @@ -165,10 +165,12 @@ def run_process_with_timeout(args, filename_in=None, filename_out=None, filename
the process. If None, the process standard error will still be
captured and returned.
@type filename_err: string
@param timeout: the number of seconds after which the process is killed.
@type timeout: int
@param cwd: the current working directory where to execute the process.
@type cwd: string
@param timeout: the number of seconds after which the process is killed.
@type timeout: int
@param shell: specifies if this command should be called through the shell
@type shell: boolean
@return: a tuple containing with the exit status, the captured output and
the captured error.
@rtype: tuple
Expand Down Expand Up @@ -221,7 +223,7 @@ def call_the_process(the_process, stdout, stderr):
stderr = open(filename_err, 'w')
else:
stderr = None
the_process = Process(args, stdin=stdin, cwd=cwd)
the_process = Process(args, shell=shell, stdin=stdin, cwd=cwd)
try:
return with_timeout(timeout, call_the_process, the_process, stdout, stderr)
except Timeout:
Expand Down

0 comments on commit 35938ec

Please sign in to comment.