当前位置: 首页>>代码示例>>Python>>正文


Python Popen.poll方法代码示例

本文整理汇总了Python中subprocess32.Popen.poll方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.poll方法的具体用法?Python Popen.poll怎么用?Python Popen.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在subprocess32.Popen的用法示例。


在下文中一共展示了Popen.poll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_playbook

# 需要导入模块: from subprocess32 import Popen [as 别名]
# 或者: from subprocess32.Popen import poll [as 别名]
def run_playbook(playbook, inventory, *args, **kwargs):
    env = ansible_env(os.environ.copy())
    cmd = ['ansible-playbook', '-i', inventory, playbook] + list(args)

    if verbosity():
        cmd += ['-' + ('v' * verbosity())]

    show_timestamp = False
    if 'timestamp' in kwargs:
        show_timestamp = kwargs['timestamp']
        del kwargs['timestamp']

    output = print
    if show_timestamp:
        output = timestamp

    logger.info('running %s', ' '.join(cmd))
    logger.debug('env: %r', env)

    process = Popen(cmd, env=env, stdout=PIPE,
                    bufsize=1, **kwargs)
    for line in iter(process.stdout.readline, b''):
        output(line[:-1])
    # empty output buffers
    process.poll()
    return process.returncode
开发者ID:AerisCloud,项目名称:AerisCloud,代码行数:28,代码来源:ansible.py

示例2: DummySim

# 需要导入模块: from subprocess32 import Popen [as 别名]
# 或者: from subprocess32.Popen import poll [as 别名]
class DummySim(ProcessWorkerThread):

    def handle_eval(self, record):
        self.process = Popen(['./sumfun_ext', array2str(record.params[0])],
                             stdout=PIPE)

        val = np.nan
        # Continuously check for new outputs from the subprocess
        while True:
            output = self.process.stdout.readline()
            if output == '' and self.process.poll() is not None:  # No new output
                break
            if output:  # New intermediate output
                try:
                    val = float(output.strip())  # Try to parse output
                    if val > 350:  # Terminate if too large
                        self.process.terminate()
                        self.finish_success(record, 350)
                        return
                except ValueError:  # If the output is nonsense we terminate
                    logging.warning("Incorrect output")
                    self.process.terminate()
                    self.finish_failure(record)
                    return

        rc = self.process.poll()  # Check the return code
        if rc < 0 or np.isnan(val):
            logging.warning("Incorrect output or crashed evaluation")
            self.finish_failure(record)
        else:
            self.finish_success(record, val)
开发者ID:NoobSajbot,项目名称:pySOT,代码行数:33,代码来源:test_subprocess_partial_info.py

示例3: run

# 需要导入模块: from subprocess32 import Popen [as 别名]
# 或者: from subprocess32.Popen import poll [as 别名]
def run(pro, *args, **kwargs):
    """
    Run vagrant within a project
    :param pro: .project.Project
    :param args: list[string]
    :param kwargs: dict[string,string]
    :return:
    """
    with cd(pro.folder()):
        # fix invalid exports for vagrant
        NFS().fix_anomalies()

        new_env = ansible_env(os.environ.copy())

        new_env['PATH'] = os.pathsep.join([
            new_env['PATH'],
            os.path.join(aeriscloud_path, 'venv/bin')
        ])
        new_env['VAGRANT_DOTFILE_PATH'] = pro.vagrant_dir()
        new_env['VAGRANT_CWD'] = pro.vagrant_working_dir()
        new_env['VAGRANT_DISKS_PATH'] = os.path.join(data_dir(), 'disks')

        # We might want to remove that or bump the verbosity level even more
        if verbosity() >= 4:
            new_env['VAGRANT_LOG'] = 'info'

        new_env['AERISCLOUD_PATH'] = aeriscloud_path
        new_env['AERISCLOUD_ORGANIZATIONS_DIR'] = os.path.join(data_dir(),
                                                               'organizations')

        org = default_organization()
        if org:
            new_env['AERISCLOUD_DEFAULT_ORGANIZATION'] = org

        organization_name = pro.organization()
        if organization_name:
            organization = Organization(organization_name)
        else:
            organization = Organization(org)

        basebox_url = organization.basebox_url()
        if basebox_url:
            new_env['VAGRANT_SERVER_URL'] = basebox_url

        args = ['vagrant'] + list(args)
        logger.debug('running: %s\nenv: %r', ' '.join(args), new_env)

        # support for the vagrant prompt
        if args[1] == 'destroy':
            return call(args, env=new_env, **kwargs)
        else:
            process = Popen(args, env=new_env, stdout=PIPE,
                            bufsize=1, **kwargs)
            for line in iter(process.stdout.readline, b''):
                timestamp(line[:-1])
            # empty output buffers
            process.poll()
            return process.returncode
开发者ID:AerisCloud,项目名称:AerisCloud,代码行数:60,代码来源:vagrant.py

示例4: run_compiler

# 需要导入模块: from subprocess32 import Popen [as 别名]
# 或者: from subprocess32.Popen import poll [as 别名]
 def run_compiler(self, language, filename, executable_name):
     args = ["g++" if language else "gcc", "-static", "-w", "-O2", filename, "-o",
             executable_name]
     self.log += ['Running: ' + ' '.join(args)]
     proc = Popen(args,
                  cwd=self.base_dir, stdin=PIPE, stdout=PIPE, stderr=PIPE)
     output = proc.communicate(timeout=self.COMPILE_TIMEOUT)
     self.log += [str(output[1])]
     if proc.poll() is None:
         try:
             self.log += ['Compile timeout.']
             proc.kill()
         except Exception:
             pass
     self.log += ["Compiler returns %d." % proc.returncode]
     if proc.returncode:
         raise CompileErrorException()
开发者ID:ruc-acm,项目名称:online-vs-platform,代码行数:19,代码来源:judge-daemon.py

示例5: check_output

# 需要导入模块: from subprocess32 import Popen [as 别名]
# 或者: from subprocess32.Popen import poll [as 别名]
def check_output(*popenargs, **kwargs):
    """
    Re-implement check_output from subprocess32, but with a timeout that kills
    child processes.

    See https://github.com/google/python-subprocess32/blob/master/subprocess32.py#L606
    """
    timeout = kwargs.pop('timeout', None)
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')
    process = Popen(stdout=PIPE, preexec_fn=os.setsid, *popenargs, **kwargs)
    try:
        output = process.communicate(timeout=timeout)[0]
    except TimeoutExpired as error:
        os.killpg(process.pid, signal.SIGINT)
        raise error
    retcode = process.poll()
    if retcode:
        raise CalledProcessError(retcode, process.args, output=output)
    return output
开发者ID:innisfree,项目名称:pymath,代码行数:22,代码来源:timeout.py

示例6: check_output

# 需要导入模块: from subprocess32 import Popen [as 别名]
# 或者: from subprocess32.Popen import poll [as 别名]
def check_output(*popenargs, **kwargs):
    r"""Run command with arguments and return its output as a byte string.
    If the exit code was non-zero it raises a CalledProcessError.  The
    CalledProcessError object will have the return code in the returncode
    attribute and output in the output attribute.
    The arguments are the same as for the Popen constructor.  Example:
    >>> check_output(["ls", "-l", "/dev/null"])
    'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'
    The stdout argument is not allowed as it is used internally.
    To capture standard error in the result, use stderr=STDOUT.
    >>> check_output(["/bin/sh", "-c",
    ...               "ls -l non_existent_file ; exit 0"],
    ...              stderr=STDOUT)
    'ls: non_existent_file: No such file or directory\n'
    """

    timeout = kwargs.pop('timeout', None)
    if 'stdout' in kwargs:
        raise ValueError('stdout argument not allowed, it will be overridden.')

    if _kill_processes.is_set():
        raise TerminateSignaled()

    process = Popen(stdout=PIPE, *popenargs, **kwargs)
    _processes.append(process)

    try:
        output, unused_err = process.communicate(timeout=timeout)
        _processes.remove(process)

    except TimeoutExpired:
        _processes.remove(process)
        process.kill()
        output, unused_err = process.communicate()
        raise TimeoutExpired(process.args, timeout, output=output)

    retcode = process.poll()
    if retcode:
        raise CalledProcessError(retcode, process.args, output=output)
    return output
开发者ID:metocean,项目名称:gregc,代码行数:42,代码来源:subprocess_thread_tool.py

示例7: run2

# 需要导入模块: from subprocess32 import Popen [as 别名]
# 或者: from subprocess32.Popen import poll [as 别名]
def run2(command, check=True, timeout=None, *args, **kwargs):
    ''' Run a command.

        If check=True (the default),
        then if return code is not zero or there is stderr output,
        raise CalledProcessError. Return any output in the exception.

        If timeout (in seconds) is set and command times out, raise TimeoutError. '''

    ''' Parts from subprocess32.check_output(). '''

    raise Exception('Deprecated. Use the sh module.')

    # use subprocess32 for timeout
    from subprocess32 import Popen, CalledProcessError, TimeoutExpired

    process = Popen(command, stdout=stdout, stderr=stderr, *args, **kwargs)
    try:
        process.wait(timeout=timeout)
    except TimeoutExpired:
        print('TimeoutExpired') #DEBUG
        #print('stdout: %s, (%d)' % (str(stdout), len(str(stdout)))) #DEBUG
        #print('stderr: %s, (%d)' % (str(stderr), len(str(stderr)))) #DEBUG
        try:
            process.kill()
            process.wait()
        finally:
            print('after kill/wait') #DEBUG
            #print('stdout: %s, (%d)' % (str(stdout), len(str(stdout)))) #DEBUG
            #print('stderr: %s, (%d)' % (str(stderr), len(str(stderr)))) #DEBUG
            raise TimeoutExpired(process.args, timeout)

    if check:
        retcode = process.poll()
        if retcode:
            raise CalledProcessError(retcode, process.args)
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:38,代码来源:utils.py


注:本文中的subprocess32.Popen.poll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。