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


Python Process.parent方法代码示例

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


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

示例1: ppid_cascade

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import parent [as 别名]
def ppid_cascade(process=None):
    if process is None:
        process = Process()
    process = process.parent()
    while process:
        yield process.pid
        process = process.parent()
开发者ID:phillipberndt,项目名称:scripts,代码行数:9,代码来源:pskill.py

示例2: _get_shell_pid

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import parent [as 别名]
def _get_shell_pid():
    """Returns parent process pid."""
    proc = Process(os.getpid())

    try:
        return proc.parent().pid
    except TypeError:
        return proc.parent.pid
开发者ID:Googulator,项目名称:thefuck,代码行数:10,代码来源:not_configured.py

示例3: get_session_conf_dir

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import parent [as 别名]
    def get_session_conf_dir(self, cleanup=False):
        """
        Tries to find the session configuration directory by looking in ~/.dnanexus_config/sessions/<PID>,
        where <PID> is pid of the parent of this process, then its parent, and so on.
        If none of those exist, the path for the immediate parent is given, even if it doesn't exist.

        If *cleanup* is True, looks up and deletes all session configuration directories that belong to nonexistent
        processes.
        """
        sessions_dir = os.path.join(self._user_conf_dir, "sessions")
        try:
            from psutil import Process, pid_exists

            if cleanup:
                try:
                    session_dirs = os.listdir(sessions_dir)
                except OSError as e:
                    # Silently skip cleanup and continue if we are unable to
                    # enumerate the session directories for any reason
                    # (including, most commonly, because the sessions dir
                    # doesn't exist)
                    session_dirs = []
                for session_dir in session_dirs:
                    try:
                        session_pid = int(session_dir)
                    except ValueError:
                        # If dir name doesn't look like an int, leave it
                        # alone
                        continue
                    if not pid_exists(session_pid):
                        rmtree(os.path.join(sessions_dir, session_dir), ignore_errors=True)

            parent_process = Process(os.getpid()).parent()
            default_session_dir = os.path.join(sessions_dir, str(parent_process.pid))
            while parent_process is not None and parent_process.pid != 0:
                session_dir = os.path.join(sessions_dir, str(parent_process.pid))
                if os.path.exists(session_dir):
                    return session_dir
                parent_process = parent_process.parent()
            return default_session_dir
        except (ImportError, IOError, AttributeError) as e:
            # We don't bundle psutil with Windows, so failure to import
            # psutil would be expected.
            if platform.system() != 'Windows':
                warn(fill("Error while retrieving session configuration: " + format_exception(e)))
        except Exception as e:
            warn(fill("Unexpected error while retrieving session configuration: " + format_exception(e)))
        return self._get_ppid_session_conf_dir(sessions_dir)
开发者ID:dnanexus,项目名称:dx-toolkit,代码行数:50,代码来源:config.py

示例4: _get_shell_from_proc

# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import parent [as 别名]
def _get_shell_from_proc():
    proc = Process(os.getpid())

    while proc is not None and proc.pid > 0:
        try:
            name = proc.name()
        except TypeError:
            name = proc.name

        name = os.path.splitext(name)[0]

        if name in shells:
            return shells[name]()

        try:
            proc = proc.parent()
        except TypeError:
            proc = proc.parent

    return Generic()
开发者ID:alexandre-paroissien,项目名称:thefuck,代码行数:22,代码来源:__init__.py


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