當前位置: 首頁>>代碼示例>>Python>>正文


Python subprocess32.TimeoutExpired方法代碼示例

本文整理匯總了Python中subprocess32.TimeoutExpired方法的典型用法代碼示例。如果您正苦於以下問題:Python subprocess32.TimeoutExpired方法的具體用法?Python subprocess32.TimeoutExpired怎麽用?Python subprocess32.TimeoutExpired使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在subprocess32的用法示例。


在下文中一共展示了subprocess32.TimeoutExpired方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: exec_command

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def exec_command(cmd, args, cwd, timeout=None):
    """
    Executes shell command inside @repo_path
    returns exec code
    """
    pipe = None
    try:
        env = os.environ
        env["PATH"] = env["NDK_TOOLCHAIN"] + "/bin:" + env["PATH"]
        pipe = Popen(args, stdin=PIPE, stdout=PIPE, cwd=cwd, env=env)
        stdout, error = pipe.communicate(timeout=timeout) if (timeout and timeout > 0) else pipe.communicate()
        logger.debug("stdout: %s", stdout)
        return pipe.returncode

    except TimeoutExpired as te:
        pipe.terminate()
        logger.error("%s timed out: %s", cmd, str(te))
        return 0

    except Exception as e:
        logger.error("%s subprocess failed: %s", cmd, str(e))
        return -1 
開發者ID:osssanitizer,項目名稱:osspolice,代碼行數:24,代碼來源:signature.py

示例2: adb_pushfile

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def adb_pushfile(adb, filepath, remote_path):
    filesize = os.path.getsize(filepath)
    pb = tqdm.tqdm(unit='B', unit_scale=True, total=filesize)
    p = adb.raw_cmd('push', filepath, remote_path)

    while True:
        try:
            p.wait(0.5)
        except subprocess.TimeoutExpired:
            pb.n = get_file_size(adb, remote_path)
            pb.refresh()
            # log.info("Progress %dM/%dM", get_file_size(remote_path) >>20, filesize >>20)
            pass
        except (KeyboardInterrupt, SystemExit):
            p.kill()
            raise
        except:
            raise
        else:
            # log.info("Success pushed into device")
            break
    pb.close() 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:24,代碼來源:install.py

示例3: run_in_subprocess

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def run_in_subprocess(cmd, check_output=False, **kwargs):
    """
    Execute command using default subprocess configuration.

    Parameters
    ----------
    cmd : string
        Command to be executed in subprocess.
    kwargs : keywords
        Options to pass to subprocess.Popen.

    Returns
    -------
    proc : Popen subprocess
        Subprocess used to run command.
    """

    logger.debug('Executing command: {0}'.format(cmd))
    config = DEFAULT_SUBPROCESS_CONFIG.copy()
    config.update(kwargs)
    if not check_output:
        if omniduct_config.logging_level < 20:
            config['stdout'] = None
            config['stderr'] = None
        else:
            config['stdout'] = open(os.devnull, 'w')
            config['stderr'] = open(os.devnull, 'w')
    timeout = config.pop('timeout', None)

    process = subprocess.Popen(cmd, **config)
    try:
        stdout, stderr = process.communicate(None, timeout=timeout)
    except subprocess.TimeoutExpired:
        os.killpg(os.getpgid(process.pid), signal.SIGINT)  # send signal to the process group, recursively killing all children
        output, unused_err = process.communicate()
        raise subprocess.TimeoutExpired(process.args, timeout, output=output)
    return SubprocessResults(returncode=process.returncode, stdout=stdout or b'', stderr=stderr or b'') 
開發者ID:airbnb,項目名稱:omniduct,代碼行數:39,代碼來源:processes.py

示例4: subproc_call

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def subproc_call(cmd, timeout=None):
    try:
        output = subprocess.check_output(
                cmd, stderr=subprocess.STDOUT,
                shell=True, timeout=timeout)
        return output
    except subprocess.TimeoutExpired as e:
        logger.warn("Command timeout!")
        logger.warn(e.output)
    except subprocess.CalledProcessError as e:
        logger.warn("Commnad failed: {}".format(e.returncode))
        logger.warn(e.output) 
開發者ID:anonymous-author1,項目名稱:DDRL,代碼行數:14,代碼來源:concurrency.py

示例5: run_proc_with_quit

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def run_proc_with_quit(proc_id, quit_dict, args, logfile=None, append=False, env=None, cwd=None):
    if logfile is None:
        logfile = os.devnull

    mode = 'ab' if append else 'wb'
    with open(logfile, mode) as logf:
        if proc_id in quit_dict:
            return None
        proc = subprocess.Popen(args, stdout=logf, stderr=subprocess.STDOUT,
                                env=env, cwd=cwd)
        retcode = None
        num_kill = 0
        timeout = 0.05
        while retcode is None and num_kill <= 2:
            try:
                retcode = proc.wait(timeout=timeout)
            except subprocess.TimeoutExpired:
                if proc_id in quit_dict:
                    if num_kill == 0:
                        proc.terminate()
                        timeout = quit_dict[proc_id]
                    elif num_kill == 1:
                        proc.kill()
                    num_kill += 1

        return proc.returncode 
開發者ID:ucb-art,項目名稱:BAG_framework,代碼行數:28,代碼來源:process.py

示例6: _end_process

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def _end_process(process):
    """End a process gently or, if necessary, forcibly."""
    try:
        process.terminate()
        process.wait(timeout=0.5)
    except OSError:
        pass  # Can't kill things that have changed UID.
    except subprocess32.TimeoutExpired:
        process.kill() 
開發者ID:perfsonar,項目名稱:pscheduler,代碼行數:11,代碼來源:program.py

示例7: subproc_call

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def subproc_call(cmd, timeout=None):
    """Execute a command with timeout, and return both STDOUT/STDERR.

    Args:
        cmd (str): the command to execute.
        timeout (float): timeout in seconds.

    Returns:
        output (bytes), retcode(int): If timeout, retcode is -1.

    """
    try:
        output = subprocess.check_output(
            cmd, stderr=subprocess.STDOUT,
            shell=True, timeout=timeout)
        return output, 0
    except subprocess.TimeoutExpired as e:
        print("Command '{}' timeout!".format(cmd))
        print(e.output.decode('utf-8'))
        return e.output, -1
    except subprocess.CalledProcessError as e:
        print("Command '{}' failed, return code={}".format(cmd, e.returncode))
        print(e.output.decode('utf-8'))
        return e.output, e.returncode
    except Exception:
        print("Command '{}' failed to run.".format(cmd))
        return "", -2 
開發者ID:blue-oil,項目名稱:blueoil,代碼行數:29,代碼來源:tune_ray.py

示例8: subproc_call

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def subproc_call(cmd, timeout=None):
    """
    Execute a command with timeout, and return both STDOUT/STDERR.

    Args:
        cmd(str): the command to execute.
        timeout(float): timeout in seconds.

    Returns:
        output(bytes), retcode(int). If timeout, retcode is -1.
    """
    try:
        output = subprocess.check_output(
            cmd, stderr=subprocess.STDOUT,
            shell=True, timeout=timeout)
        return output, 0
    except subprocess.TimeoutExpired as e:
        logger.warn("Command '{}' timeout!".format(cmd))
        logger.warn(e.output.decode('utf-8'))
        return e.output, -1
    except subprocess.CalledProcessError as e:
        logger.warn("Command '{}' failed, return code={}".format(cmd, e.returncode))
        logger.warn(e.output.decode('utf-8'))
        return e.output, e.returncode
    except Exception:
        logger.warn("Command '{}' failed to run.".format(cmd))
        return "", -2 
開發者ID:microsoft,項目名稱:petridishnn,代碼行數:29,代碼來源:concurrency.py

示例9: _grep_for_dep_lines

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def _grep_for_dep_lines(self, query_str, include_globs, exclude_globs):
        arg_list =['zipgrep', query_str, self.temp_file_name]
        arg_list += include_globs
        arg_list.append("-x")
        arg_list += exclude_globs
        start = time()

        try:
            print "Running zipgrep: '{}'".format(" ".join(arg_list))
            self.dep_lines = subprocess32.check_output(
                arg_list,
                timeout=90
            )

        except subprocess32.CalledProcessError:
            # heroku throws an error here when there are no dep lines to find.
            # but it's fine. there just aren't no lines.
            pass

        except subprocess32.TimeoutExpired:
            # too many files, we'll skip it and move on.
            self.error = "grep_timeout"
            pass

        finally:
            self.grep_elapsed = elapsed(start, 4)
            #print "found these dep lines: {}".format(self.dep_lines)
            print "finished dep lines search in {} sec".format(self.grep_elapsed) 
開發者ID:ourresearch,項目名稱:depsy,代碼行數:30,代碼來源:zip_getter.py

示例10: _launch_webdriver

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def _launch_webdriver(self):
        print("start chromedriver instance")
        p = subprocess.Popen(['chromedriver', '--port='+str(self._port)])
        try:
            p.wait(timeout=2.0)
            return False
        except subprocess.TimeoutExpired:
            return True 
開發者ID:NetEaseGame,項目名稱:ATX,代碼行數:10,代碼來源:chromedriver.py

示例11: watcher_getter

# 需要導入模塊: import subprocess32 [as 別名]
# 或者: from subprocess32 import TimeoutExpired [as 別名]
def watcher_getter(request, services_log):
    """Popen object of given executable name and it's arguments.

    Wait for the process to start.
    Add finalizer to properly stop it.
    """
    orig_request = request

    def watcher_getter_function(name, arguments=None, kwargs=None, timeout=20, checker=None, request=None):
        if request is None:
            warnings.warn('Omitting the `request` parameter will result in an unstable order of finalizers.')
            request = orig_request
        executable = find_executable(name)
        assert executable, 'You have to install {0} executable.'.format(name)

        cmd = [name] + (arguments or [])

        services_log.debug('Starting {0}: {1}'.format(name, arguments))

        watcher = subprocess.Popen(
            cmd, **(kwargs or {}))

        def finalize():
            try:
                watcher.terminate()
            except OSError:
                pass
            if watcher.returncode is None:
                try:
                    watcher.communicate(timeout=timeout / 2)
                except subprocess.TimeoutExpired:
                    watcher.kill()
                    watcher.communicate(timeout=timeout / 2)
        request.addfinalizer(finalize)

        # Wait for the service to start.
        times = 0
        while not checker():
            if watcher.returncode is not None:
                raise Exception("Error running {0}".format(name))

            if times > timeout:
                raise Exception('The {0} service checked did not succeed!'.format(name))

            time.sleep(1)
            times += 1

        return watcher

    return watcher_getter_function 
開發者ID:pytest-dev,項目名稱:pytest-services,代碼行數:52,代碼來源:service.py


注:本文中的subprocess32.TimeoutExpired方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。