本文整理汇总了Python中errno.ESRCH属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ESRCH属性的具体用法?Python errno.ESRCH怎么用?Python errno.ESRCH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.ESRCH属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: del_route
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def del_route(self, prefix):
if not self.platform_supported or self._simulated_interfaces:
return False
if self._table_nr == -1:
return False
dst = packet_common.ip_prefix_str(prefix)
try:
self.ipr.route('del', table=self._table_nr, dst=dst, proto=RTPROT_RIFT,
priority=RTPRIORITY_RIFT)
except pyroute2.netlink.exceptions.NetlinkError as err:
if err.code != errno.ESRCH: # It is not an error to delete a non-existing route
self.error("Netlink error \"%s\" deleting route to %s", err, dst)
return False
except OSError as err:
self.error("OS error \"%s\" deleting route to %s", err, dst)
return False
else:
self.debug("Delete route to %s", prefix)
return True
示例2: validate
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def validate(self):
""" Validate pidfile and make it stale if needed"""
if not self.fname:
return
try:
with open(self.fname, "r") as f:
try:
wpid = int(f.read())
except ValueError:
return
try:
os.kill(wpid, 0)
return wpid
except OSError as e:
if e.args[0] == errno.ESRCH:
return
raise
except IOError as e:
if e.args[0] == errno.ENOENT:
return
raise
示例3: kill_worker
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def kill_worker(self, pid, sig):
"""\
Kill a worker
:attr pid: int, worker pid
:attr sig: `signal.SIG*` value
"""
try:
os.kill(pid, sig)
except OSError as e:
if e.errno == errno.ESRCH:
try:
worker = self.WORKERS.pop(pid)
worker.tmp.close()
self.cfg.worker_exit(self, worker)
return
except (KeyError, OSError):
return
raise
示例4: kill_process
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def kill_process(pid, sig=None):
"""Try to send signal to given process."""
if sig is None:
sig = signal.SIGKILL # set default lazily, otherwise importing fails on Windows
try:
os.kill(pid, sig)
except OSError as e:
if e.errno == errno.ESRCH:
# process itself returned and exited before killing
logging.debug(
"Failure %s while killing process %s with signal %s: %s",
e.errno,
pid,
sig,
e.strerror,
)
else:
logging.warning(
"Failure %s while killing process %s with signal %s: %s",
e.errno,
pid,
sig,
e.strerror,
)
示例5: __exit__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def __exit__(self, exc_type, exc_value, traceback):
try:
self.child.terminate()
except OSError as error:
if error.errno == errno.ESRCH:
return
raise
while True:
line = self.child.stderr.readline()
if not line:
break
sys.stderr.write(line)
self.child.wait()
shutil.rmtree(self.data_path)
示例6: is_running
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def is_running(self):
if not self.pidfile.exists():
return False
if not self.pidfile.isfile():
raise Exception("pidfile '%s' is not a file" % (self.pidfile, ))
try:
pid = int(self.__pidfile.open().readline(16))
except:
self.logger.exception("Error reading pidfile %s" % (self.pidfile))
raise
try:
os.kill(pid, 0)
return True
except OSError as e:
if e.errno == errno.ESRCH:
return False
raise
示例7: wrap_exceptions
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def wrap_exceptions(fun):
"""Call callable into a try/except clause and translate ENOENT,
EACCES and EPERM in NoSuchProcess or AccessDenied exceptions.
"""
def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
except EnvironmentError as err:
# support for private module import
if (NoSuchProcess is None or AccessDenied is None or
ZombieProcess is None):
raise
# ENOENT (no such file or directory) gets raised on open().
# ESRCH (no such process) can get raised on read() if
# process is gone in meantime.
if err.errno in (errno.ENOENT, errno.ESRCH):
if not pid_exists(self.pid):
raise NoSuchProcess(self.pid, self._name)
else:
raise ZombieProcess(self.pid, self._name, self._ppid)
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(self.pid, self._name)
raise
return wrapper
示例8: _send_signal
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def _send_signal(self, sig):
assert not self.pid < 0, self.pid
if self.pid == 0:
# see "man 2 kill"
raise ValueError(
"preventing sending signal to process with PID 0 as it "
"would affect every process in the process group of the "
"calling process (os.getpid()) instead of PID 0")
try:
os.kill(self.pid, sig)
except OSError as err:
if err.errno == errno.ESRCH:
if OPENBSD and pid_exists(self.pid):
# We do this because os.kill() lies in case of
# zombie processes.
raise ZombieProcess(self.pid, self._name, self._ppid)
else:
self._gone = True
raise NoSuchProcess(self.pid, self._name)
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(self.pid, self._name)
raise
示例9: wrap_exceptions
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def wrap_exceptions(fun):
"""Decorator which translates bare OSError exceptions into
NoSuchProcess and AccessDenied.
"""
@functools.wraps(fun)
def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
except OSError as err:
if self.pid == 0:
if 0 in pids():
raise AccessDenied(self.pid, self._name)
else:
raise
if err.errno == errno.ESRCH:
if not pid_exists(self.pid):
raise NoSuchProcess(self.pid, self._name)
else:
raise ZombieProcess(self.pid, self._name, self._ppid)
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(self.pid, self._name)
raise
return wrapper
示例10: wrap_exceptions_procfs
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def wrap_exceptions_procfs(inst):
"""Same as above, for routines relying on reading /proc fs."""
try:
yield
except EnvironmentError as err:
# ENOENT (no such file or directory) gets raised on open().
# ESRCH (no such process) can get raised on read() if
# process is gone in meantime.
if err.errno in (errno.ENOENT, errno.ESRCH):
if not pid_exists(inst.pid):
raise NoSuchProcess(inst.pid, inst._name)
else:
raise ZombieProcess(inst.pid, inst._name, inst._ppid)
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(inst.pid, inst._name)
raise
示例11: get_all_inodes
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def get_all_inodes(self):
inodes = {}
for pid in pids():
try:
inodes.update(self.get_proc_inodes(pid))
except OSError as err:
# os.listdir() is gonna raise a lot of access denied
# exceptions in case of unprivileged user; that's fine
# as we'll just end up returning a connection with PID
# and fd set to None anyway.
# Both netstat -an and lsof does the same so it's
# unlikely we can do any better.
# ENOENT just means a PID disappeared on us.
if err.errno not in (
errno.ENOENT, errno.ESRCH, errno.EPERM, errno.EACCES):
raise
return inodes
示例12: ppid_map
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def ppid_map():
"""Obtain a {pid: ppid, ...} dict for all running processes in
one shot. Used to speed up Process.children().
"""
ret = {}
procfs_path = get_procfs_path()
for pid in pids():
try:
with open_binary("%s/%s/stat" % (procfs_path, pid)) as f:
data = f.read()
except EnvironmentError as err:
# Note: we should be able to access /stat for all processes
# aka it's unlikely we'll bump into EPERM, which is good.
if err.errno not in (errno.ENOENT, errno.ESRCH):
raise
else:
rpar = data.rfind(b')')
dset = data[rpar + 2:].split()
ppid = int(dset[1])
ret[pid] = ppid
return ret
示例13: wrap_exceptions
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def wrap_exceptions(fun):
"""Decorator which translates bare OSError and IOError exceptions
into NoSuchProcess and AccessDenied.
"""
@functools.wraps(fun)
def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
except EnvironmentError as err:
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(self.pid, self._name)
# ESRCH (no such process) can be raised on read() if
# process is gone in the meantime.
if err.errno == errno.ESRCH:
raise NoSuchProcess(self.pid, self._name)
# ENOENT (no such file or directory) can be raised on open().
if err.errno == errno.ENOENT and not os.path.exists("%s/%s" % (
self._procfs_path, self.pid)):
raise NoSuchProcess(self.pid, self._name)
# Note: zombies will keep existing under /proc until they're
# gone so there's no way to distinguish them in here.
raise
return wrapper
示例14: exe
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def exe(self):
try:
return readlink("%s/%s/exe" % (self._procfs_path, self.pid))
except OSError as err:
if err.errno in (errno.ENOENT, errno.ESRCH):
# no such file error; might be raised also if the
# path actually exists for system processes with
# low pids (about 0-20)
if os.path.lexists("%s/%s" % (self._procfs_path, self.pid)):
return ""
else:
if not pid_exists(self.pid):
raise NoSuchProcess(self.pid, self._name)
else:
raise ZombieProcess(self.pid, self._name, self._ppid)
if err.errno in (errno.EPERM, errno.EACCES):
raise AccessDenied(self.pid, self._name)
raise
示例15: memory_maps
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ESRCH [as 别名]
def memory_maps(self):
try:
raw = cext.proc_memory_maps(self.pid)
except OSError as err:
# XXX - can't use wrap_exceptions decorator as we're
# returning a generator; probably needs refactoring.
if err.errno in ACCESS_DENIED_ERRSET:
raise AccessDenied(self.pid, self._name)
if err.errno == errno.ESRCH:
raise NoSuchProcess(self.pid, self._name)
raise
else:
for addr, perm, path, rss in raw:
path = convert_dos_path(path)
if not PY3:
assert isinstance(path, unicode), type(path)
path = py2_strencode(path)
addr = hex(addr)
yield (addr, perm, path, rss)