本文整理汇总了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()
示例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
示例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)
示例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()