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


Python Popen.name方法代码示例

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


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

示例1: run

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import name [as 别名]
    def run(self):
        if "Running Processes" not in self.rawConfig:
            self.logger.warning("Could not find Running Processes section in config")
            return {}

        if "process_list" not in self.rawConfig["Running Processes"]:
            self.logger.warning("Could not find list of processes to watch")
            return {}

        processes = []
        processNames = self.rawConfig["Running Processes"]["process_list"]

        for processName in processNames.split(","):
            p = Popen(["pgrep", processName], stderr=PIPE)
            p.name = processName
            processes.append(p)

        Pool(len(processes)).map(self.extractResult, processes)

        return self.data
开发者ID:itorres,项目名称:sd-agent-plugins,代码行数:22,代码来源:RunningProcesses.py

示例2: cmd

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import name [as 别名]
def cmd(command):
    stream = False
    timeout = 60
    output = []
    try:
        process = Popen(shlex.split(command), stdout=PIPE, stderr=STDOUT, stdin=None)
        process.name = command
        # start the timer if we specified a timeout
        if timeout:
            proctimer = threading.Timer(timeout, _timeout, (process,))
            proctimer.start()
        for line in iter(process.stdout.readline, ''):
            if stream:
                print(line.rstrip('\n'))
            output.append(line.rstrip('\n'))
        # when finished, get the exit code
        returncode = process.wait()
    except OSError as e:
        output.append(e.strerror.rstrip('\n'))
        returncode = e.errno
    except (KeyboardInterrupt, SystemExit):
        # need to clean up the timing thread here
        if timeout:
            proctimer.cancel()
        raise
    else:
        # Stop the timer
        if timeout:
            proctimer.cancel()
    if returncode == -9:
        output.append("Command '%s' timed out (longer than %ss)" % (command, timeout))
    return returncode, '\n'.join(output)
开发者ID:EvanKrall,项目名称:paasta,代码行数:34,代码来源:graceful_container_drain.py

示例3: connect

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import name [as 别名]
 def connect(self):
     cmd = ['ssh']
     cmd.extend(self._flags)
     cmd.extend([self._host, "-p", self._port, "-l", self._user])
     conn = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
     conn.name = self._name
     conn.agent = self
     self.connection = conn
开发者ID:mzlee,项目名称:comnctl,代码行数:10,代码来源:agent.py

示例4: _run

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import name [as 别名]
def _run(command, env=os.environ, timeout=None, log=False, stream=False, stdin=None, **kwargs):
    """Given a command, run it. Return a tuple of the return code and any
    output.

    :param timeout: If specified, the command will be terminated after timeout
        seconds.
    :param log: If True, the _log will be handled by _run. If set, it is mandatory
        to pass at least a :service: and a :component: parameter. Optionally you
        can pass :cluster:, :instance: and :loglevel: parameters for logging.
    We wanted to use plumbum instead of rolling our own thing with
    subprocess.Popen but were blocked by
    https://github.com/tomerfiliba/plumbum/issues/162 and our local BASH_FUNC
    magic.
    """
    output = []
    if log:
        service = kwargs['service']
        component = kwargs['component']
        cluster = kwargs.get('cluster', ANY_CLUSTER)
        instance = kwargs.get('instance', ANY_INSTANCE)
        loglevel = kwargs.get('loglevel', DEFAULT_LOGLEVEL)
    try:
        process = Popen(shlex.split(command), stdout=PIPE, stderr=STDOUT, stdin=stdin, env=env)
        process.name = command
        # start the timer if we specified a timeout
        if timeout:
            proctimer = threading.Timer(timeout, _timeout, (process,))
            proctimer.start()
        for line in iter(process.stdout.readline, ''):
            if stream:
                print(line.rstrip('\n'))
            if log:
                _log(
                    service=service,
                    line=line.rstrip('\n'),
                    component=component,
                    level=loglevel,
                    cluster=cluster,
                    instance=instance,
                )
            output.append(line.rstrip('\n'))
        # when finished, get the exit code
        returncode = process.wait()
    except OSError as e:
        if log:
            _log(
                service=service,
                line=e.strerror.rstrip('\n'),
                component=component,
                level=loglevel,
                cluster=cluster,
                instance=instance,
            )
        output.append(e.strerror.rstrip('\n'))
        returncode = e.errno
    except (KeyboardInterrupt, SystemExit):
        # need to clean up the timing thread here
        if timeout:
            proctimer.cancel()
        raise
    # Stop the timer
    if timeout:
        proctimer.cancel()
    if returncode == -9:
        output.append("Command '%s' timed out (longer than %ss)" % (command, timeout))
    return returncode, '\n'.join(output)
开发者ID:timopek,项目名称:paasta,代码行数:68,代码来源:utils.py


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