(args, cwd=None, shell=False, kill_tree=True, timeout=-1, env=None,
        stdout=PIPE, stderr=PIPE)
return p.returncode, stdout, stderr
Run a command with a timeout after which it will be forcibly
    killed.

    # this is code by Alex Martelli
    http://stackoverflow.com/
    questions/1191374/subprocess-with-timeout/#answer-3326559
Run a command with a timeout after which it will be forcibly
    killed.
Run a command with a timeout after which it will be forcibly killed .
def run(args, cwd=None, shell=False, kill_tree=True, timeout=-1, env=None,
        stdout=PIPE, stderr=PIPE):
    '''
    Run a command with a timeout after which it will be forcibly
    killed.

    # this is code by Alex Martelli
    http://stackoverflow.com/
    questions/1191374/subprocess-with-timeout/#answer-3326559
    '''
    class Alarm(Exception):
        pass

    def alarm_handler(signum, frame):
        raise Alarm

    p = Popen(
        args, shell=shell, cwd=cwd, stdout=stdout, stderr=stderr, env=env)
    if timeout != -1:
        signal(SIGALRM, alarm_handler)
        alarm(timeout)
    try:
        stdout, stderr = p.communicate()
        if timeout != -1:
            alarm(0)
    except Alarm:
        pids = [p.pid]
        if kill_tree:
            pids.extend(get_process_children(p.pid))
        for pid in pids:
            # process might have died before getting to this line
            # so wrap to avoid OSError: no such process
            try:
                kill(pid, SIGKILL)
            except OSError:
                pass
        return -9, '', ''
    return p.returncode, stdout, stderr
def run ( args , cwd = None , shell = False , kill_tree = True , timeout = - 1 , env = None , stdout = PIPE , stderr = PIPE ) : class Alarm ( Exception ) : pass def alarm_handler ( signum , frame ) : raise Alarm p = Popen ( args , shell = shell , cwd = cwd , stdout = stdout , stderr = stderr , env = env ) if timeout != - 1 : signal ( SIGALRM , alarm_handler ) alarm ( timeout ) try : stdout , stderr = p . communicate ( ) if timeout != - 1 : alarm ( 0 ) except Alarm : pids = [ p . pid ] if kill_tree : pids . extend ( get_process_children ( p . pid ) ) for pid in pids : # process might have died before getting to this line # so wrap to avoid OSError: no such process try : kill ( pid , SIGKILL ) except OSError : pass return - 9 , '' , '' return p . returncode , stdout , stderr