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


Python Popen.children方法代码示例

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


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

示例1: Run

# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import children [as 别名]

#.........这里部分代码省略.........
            :type path: str
            """
            logger.error("%s not found", path)
            e3.log.debug('PATH=%s', os.environ['PATH'])
            raise OSError(errno.ENOENT,
                          'No such file or directory, %s not found' % path)

        # Try to send an helpful message if one of the executable has not
        # been found.
        if isinstance(cmds[0], basestring):
            if which(cmds[0], default=None) is None:
                not_found(cmds[0])
        else:
            for cmd in cmds:
                if which(cmd[0], default=None) is None:
                    not_found(cmd[0])

    def wait(self):
        """Wait until process ends and return its status.

        :return: exit code of the process
        :rtype: int
        """
        if self.status is not None:
            # Wait has already been called
            return self.status

        # If there is no pipe in the loop then just do a wait. Otherwise
        # in order to avoid blocked processes due to full pipes, use
        # communicate.
        if self.output_file.fd != subprocess.PIPE and \
                self.error_file.fd != subprocess.PIPE and \
                self.input_file.fd != subprocess.PIPE:
            self.status = self.internal.wait()
        else:
            tmp_input = None
            if self.input_file.fd == subprocess.PIPE:
                tmp_input = self.input_file.get_command()

            (self.out, self.err) = self.internal.communicate(tmp_input)
            self.status = self.internal.returncode

        self.close_files()
        return self.status

    def poll(self):
        """Check the process status and set self.status if available.

        This method checks whether the underlying process has exited
        or not. If it hasn't, then it just returns None immediately.
        Otherwise, it stores the process' exit code in self.status
        and then returns it.

        :return: None if the process is still alive; otherwise, returns
          the process exit status.
        :rtype: int | None
        """
        if self.status is not None:
            # Process is already terminated and wait been called
            return self.status

        result = self.internal.poll()

        if result is not None:
            # Process is finished, call wait to finalize it (closing handles,
            # ...)
            return self.wait()
        else:
            return None

    def kill(self):
        """Kill the process."""
        self.internal.kill()

    def interrupt(self):
        """Send SIGINT CTRL_C_EVENT to the process."""
        # On windows CTRL_C_EVENT is available and SIGINT is not;
        # and the other way around on other platforms.
        interrupt_signal = getattr(signal, 'CTRL_C_EVENT', signal.SIGINT)
        self.internal.send_signal(interrupt_signal)

    def is_running(self):
        """Check whether the process is running.

        :rtype: bool
        """
        if psutil is None:
            # psutil not imported, use our is_running function
            return is_running(self.pid)
        else:
            return self.internal.is_running()

    def children(self):
        """Return list of child processes (using psutil).

        :rtype: list[psutil.Process]
        """
        if psutil is None:
            raise NotImplementedError('Run.children() require psutil')
        return self.internal.children()
开发者ID:AdaCore,项目名称:e3-core,代码行数:104,代码来源:process.py


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