本文整理汇总了Python中psutil.Popen.is_running方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.is_running方法的具体用法?Python Popen.is_running怎么用?Python Popen.is_running使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil.Popen
的用法示例。
在下文中一共展示了Popen.is_running方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Process
# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import is_running [as 别名]
#.........这里部分代码省略.........
def info(self):
"""Return process info.
The info returned is a mapping with these keys:
- **mem_info1**: Resident Set Size Memory in bytes (RSS)
- **mem_info2**: Virtual Memory Size in bytes (VMS).
- **cpu**: % of cpu usage.
- **mem**: % of memory usage.
- **ctime**: process CPU (user + system) time in seconds.
- **pid**: process id.
- **username**: user name that owns the process.
- **nice**: process niceness (between -20 and 20)
- **cmdline**: the command line the process was run with.
"""
try:
info = get_info(self._worker)
except NoSuchProcess:
return "No such process (stopped?)"
info["age"] = self.age()
info["started"] = self.started
info["children"] = []
for child in self._worker.get_children():
info["children"].append(get_info(child))
return info
def children(self):
"""Return a list of children pids."""
return [child.pid for child in self._worker.get_children()]
def is_child(self, pid):
"""Return True is the given *pid* is a child of that process."""
pids = [child.pid for child in self._worker.get_children()]
if pid in pids:
return True
return False
@debuglog
def send_signal_child(self, pid, signum):
"""Send signal *signum* to child *pid*."""
children = dict([(child.pid, child)
for child in self._worker.get_children()])
children[pid].send_signal(signum)
@debuglog
def send_signal_children(self, signum):
"""Send signal *signum* to all children."""
for child in self._worker.get_children():
try:
child.send_signal(signum)
except OSError as e:
if e.errno != errno.ESRCH:
raise
@property
def status(self):
"""Return the process status as a constant
- RUNNING
- DEAD_OR_ZOMBIE
- UNEXISTING
- OTHER
"""
try:
if self._worker.status in (STATUS_ZOMBIE, STATUS_DEAD):
return DEAD_OR_ZOMBIE
except NoSuchProcess:
return UNEXISTING
if self._worker.is_running():
return RUNNING
return OTHER
@property
def pid(self):
"""Return the *pid*"""
return self._worker.pid
@property
def stdout(self):
"""Return the *stdout* stream"""
return self._worker.stdout
@property
def stderr(self):
"""Return the *stdout* stream"""
return self._worker.stderr
def __eq__(self, other):
return self is other
def __lt__(self, other):
return self.started < other.started
def __gt__(self, other):
return self.started > other.started
示例2: Process
# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import is_running [as 别名]
#.........这里部分代码省略.........
The info returned is a mapping with these keys:
- **mem_info1**: Resident Set Size Memory in bytes (RSS)
- **mem_info2**: Virtual Memory Size in bytes (VMS).
- **cpu**: % of cpu usage.
- **mem**: % of memory usage.
- **ctime**: process CPU (user + system) time in seconds.
- **pid**: process id.
- **username**: user name that owns the process.
- **nice**: process niceness (between -20 and 20)
- **cmdline**: the command line the process was run with.
"""
try:
info = get_info(self._worker)
except NoSuchProcess:
return "No such process (stopped?)"
info["age"] = self.age()
info["started"] = self.started
info["children"] = []
info['wid'] = self.wid
for child in get_children(self._worker):
info["children"].append(get_info(child))
return info
def children(self):
"""Return a list of children pids."""
return [child.pid for child in get_children(self._worker)]
def is_child(self, pid):
"""Return True is the given *pid* is a child of that process."""
pids = [child.pid for child in get_children(self._worker)]
if pid in pids:
return True
return False
@debuglog
def send_signal_child(self, pid, signum):
"""Send signal *signum* to child *pid*."""
children = dict((child.pid, child)
for child in get_children(self._worker))
try:
children[pid].send_signal(signum)
except KeyError:
raise NoSuchProcess(pid)
@debuglog
def send_signal_children(self, signum, recursive=False):
"""Send signal *signum* to all children."""
for child in get_children(self._worker, recursive):
try:
child.send_signal(signum)
except OSError as e:
if e.errno != errno.ESRCH:
raise
@property
def status(self):
"""Return the process status as a constant
- RUNNING
- DEAD_OR_ZOMBIE
- UNEXISTING
- OTHER
"""
try:
if get_status(self._worker) in (STATUS_ZOMBIE, STATUS_DEAD):
return DEAD_OR_ZOMBIE
except NoSuchProcess:
return UNEXISTING
if self._worker.is_running():
return RUNNING
return OTHER
@property
def pid(self):
"""Return the *pid*"""
return self._worker.pid
@property
def stdout(self):
"""Return the *stdout* stream"""
return self._worker.stdout
@property
def stderr(self):
"""Return the *stdout* stream"""
return self._worker.stderr
def __eq__(self, other):
return self is other
def __lt__(self, other):
return self.started < other.started
def __gt__(self, other):
return self.started > other.started
示例3: Run
# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import is_running [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()
示例4: Process
# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import is_running [as 别名]
#.........这里部分代码省略.........
def stop(self):
"""Terminate the process."""
try:
if self._worker.poll() is None:
return self._worker.terminate()
finally:
self._worker.stderr.close()
self._worker.stdout.close()
def age(self):
"""Return the age of the process in seconds."""
return time.time() - self.started
def info(self):
"""Return process info.
The info returned is a mapping with these keys:
- **mem_info1**: Resident Set Size Memory in bytes (RSS)
- **mem_info2**: Virtual Memory Size in bytes (VMS).
- **cpu**: % of cpu usage.
- **mem**: % of memory usage.
- **ctime**: process CPU (user + system) time in seconds.
- **pid**: process id.
- **username**: user name that owns the process.
- **nice**: process niceness (between -20 and 20)
- **cmdline**: the command line the process was run with.
"""
try:
info = get_info(self._worker)
except NoSuchProcess:
return "No such process (stopped?)"
info["children"] = []
for child in self._worker.get_children():
info["children"].append(get_info(child))
return info
def children(self):
"""Return a list of children pids."""
return [child.pid for child in self._worker.get_children()]
def is_child(self, pid):
"""Return True is the given *pid* is a child of that process."""
pids = [child.pid for child in self._worker.get_children()]
if pid in pids:
return True
return False
@debuglog
def send_signal_child(self, pid, signum):
"""Send signal *signum* to child *pid*."""
children = dict([(child.pid, child) \
for child in self._worker.get_children()])
children[pid].send_signal(signum)
@debuglog
def send_signal_children(self, signum):
"""Send signal *signum* to all children."""
for child in self._worker.get_children():
try:
child.send_signal(signum)
except OSError as e:
if e.errno != errno.ESRCH:
raise
@property
def status(self):
"""Return the process status as a constant
- RUNNING
- DEAD_OR_ZOMBIE
- OTHER
"""
try:
if self._worker.status in (STATUS_ZOMBIE, STATUS_DEAD):
return DEAD_OR_ZOMBIE
except NoSuchProcess:
return OTHER
if self._worker.is_running():
return RUNNING
return OTHER
@property
def pid(self):
"""Return the *pid*"""
return self._worker.pid
@property
def stdout(self):
"""Return the *stdout* stream"""
return self._worker.stdout
@property
def stderr(self):
"""Return the *stdout* stream"""
return self._worker.stderr
示例5: Process
# 需要导入模块: from psutil import Popen [as 别名]
# 或者: from psutil.Popen import is_running [as 别名]
#.........这里部分代码省略.........
"""Sends a signal **sig** to the process."""
return self._worker.send_signal(sig)
@debuglog
def stop(self):
"""Terminate the process."""
if self._worker.poll() is None:
return self._worker.terminate()
def age(self):
"""Return the age of the process in seconds."""
return time.time() - self.started
def info(self):
"""Return process info.
The info returned is a mapping with these keys:
- **mem_info1**: Resident Set Size Memory in bytes (RSS)
- **mem_info2**: Virtual Memory Size in bytes (VMS).
- **cpu**: % of cpu usage.
- **mem**: % of memory usage.
- **ctime**: process CPU (user + system) time in seconds.
- **pid**: process id.
- **username**: user name that owns the process.
- **nice**: process niceness (between -20 and 20)
- **cmdline**: the command line the process was run with.
"""
try:
info = get_info(self._worker)
except NoSuchProcess:
return "No such process (stopped?)"
info["children"] = []
for child in self._worker.get_children():
info["children"].append(get_info(child))
return info
def children(self):
"""Return a list of children pids."""
return [child.pid for child in self._worker.get_children()]
def is_child(self, pid):
"""Return True is the given *pid* is a child of that process."""
pids = [child.pid for child in self._worker.get_children()]
if pid in pids:
return True
return False
@debuglog
def send_signal_child(self, pid, signum):
"""Send signal *signum* to child *pid*."""
children = dict([(child.pid, child) \
for child in self._worker.get_children()])
children[pid].send_signal(signum)
@debuglog
def send_signal_children(self, signum):
"""Send signal *signum* to all children."""
for child in self._worker.get_children():
try:
child.send_signal(signum)
except OSError as e:
if e.errno != errno.ESRCH:
raise
@property
def status(self):
"""Return the process status as a constant
- RUNNING
- DEAD_OR_ZOMBIE
- OTHER
"""
try:
if self._worker.status in (STATUS_ZOMBIE, STATUS_DEAD):
return DEAD_OR_ZOMBIE
except NoSuchProcess:
return OTHER
if self._worker.is_running():
return RUNNING
return OTHER
@property
def pid(self):
"""Return the *pid*"""
return self._worker.pid
@property
def stdout(self):
"""Return the *stdout* stream"""
return self._worker.stdout
@property
def stderr(self):
"""Return the *stdout* stream"""
return self._worker.stderr