本文整理汇总了Python中psutil._compat.callable函数的典型用法代码示例。如果您正苦于以下问题:Python callable函数的具体用法?Python callable怎么用?Python callable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callable函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: call
def call(self, function, *args, **kwargs):
try:
obj = getattr(self.proc, function)
if callable(obj):
obj(*args, **kwargs)
except psutil.Error:
pass
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:7,代码来源:test_memory_leaks.py
示例2: call
def call(p, attr):
args = ()
attr = getattr(p, name, None)
if attr is not None and callable(attr):
if name == 'rlimit':
args = (psutil.RLIMIT_NOFILE,)
attr(*args)
else:
attr
开发者ID:jomann09,项目名称:psutil,代码行数:9,代码来源:test_posix.py
示例3: wrapper
def wrapper(self, *args, **kwargs):
try:
return callable(self, *args, **kwargs)
except OSError:
err = sys.exc_info()[1]
if err.errno in ACCESS_DENIED_SET:
raise psutil.AccessDenied(None, None)
if err.errno == errno.ESRCH:
raise psutil.NoSuchProcess(None, None)
raise
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:10,代码来源:_windows.py
示例4: as_dict
def as_dict(self, attrs=[], ad_value=None):
"""Utility method returning process information as a hashable
dictionary.
If 'attrs' is specified it must be a list of strings reflecting
available Process class's attribute names (e.g. ['get_cpu_times',
'name']) else all public (read only) attributes are assumed.
'ad_value' is the value which gets assigned to a dict key in case
AccessDenied exception is raised when retrieving that particular
process information.
"""
excluded_names = set(['send_signal', 'suspend', 'resume', 'terminate',
'kill', 'wait', 'is_running', 'as_dict', 'parent',
'get_children', 'nice'])
retdict = dict()
for name in set(attrs or dir(self)):
if name.startswith('_'):
continue
if name.startswith('set_'):
continue
if name in excluded_names:
continue
try:
attr = getattr(self, name)
if callable(attr):
if name == 'get_cpu_percent':
ret = attr(interval=0)
else:
ret = attr()
else:
ret = attr
except AccessDenied:
ret = ad_value
except NotImplementedError:
# in case of not implemented functionality (may happen
# on old or exotic systems) we want to crash only if
# the user explicitly asked for that particular attr
if attrs:
raise
continue
if name.startswith('get'):
if name[3] == '_':
name = name[4:]
elif name == 'getcwd':
name = 'cwd'
retdict[name] = ret
return retdict
开发者ID:130s,项目名称:rqt_top,代码行数:48,代码来源:__init__.py
示例5: call
def call(self, function, *args, **kwargs):
if callable(function):
if '_exc' in kwargs:
exc = kwargs.pop('_exc')
self.assertRaises(exc, function, *args, **kwargs)
else:
try:
function(*args, **kwargs)
except psutil.Error:
pass
else:
meth = getattr(self.proc, function)
if '_exc' in kwargs:
exc = kwargs.pop('_exc')
self.assertRaises(exc, meth, *args, **kwargs)
else:
try:
meth(*args, **kwargs)
except psutil.Error:
pass
开发者ID:sethp-jive,项目名称:psutil,代码行数:20,代码来源:test_memory_leaks.py
示例6: call
def call(p, attr):
attr = getattr(p, name, None)
if attr is not None and callable(attr):
attr()
else:
attr
开发者ID:baweaver,项目名称:psutil,代码行数:6,代码来源:_windows.py
示例7: call
def call(self, function, *args, **kwargs):
fun = function if callable(function) else getattr(psutil, function)
fun(*args, **kwargs)
开发者ID:4sp1r3,项目名称:psutil,代码行数:3,代码来源:test_memory_leaks.py
示例8: call
def call(self, function, *args, **kwargs):
p = psutil.Process(os.getpid())
obj = getattr(p, function)
if callable(obj):
obj(*args, **kwargs)
开发者ID:THM1,项目名称:fly-laserbox,代码行数:5,代码来源:test_memory_leaks.py
示例9: test_fetch_all
def test_fetch_all(self):
valid_procs = 0
excluded_names = set([
'send_signal', 'suspend', 'resume', 'terminate', 'kill', 'wait',
'as_dict', 'parent', 'children', 'memory_info_ex', 'oneshot',
])
if LINUX and not HAS_RLIMIT:
excluded_names.add('rlimit')
attrs = []
for name in dir(psutil.Process):
if name.startswith("_"):
continue
if name in excluded_names:
continue
attrs.append(name)
default = object()
failures = []
for p in psutil.process_iter():
with p.oneshot():
for name in attrs:
ret = default
try:
args = ()
kwargs = {}
attr = getattr(p, name, None)
if attr is not None and callable(attr):
if name == 'rlimit':
args = (psutil.RLIMIT_NOFILE,)
elif name == 'memory_maps':
kwargs = {'grouped': False}
ret = attr(*args, **kwargs)
else:
ret = attr
valid_procs += 1
except NotImplementedError:
msg = "%r was skipped because not implemented" % (
self.__class__.__name__ + '.test_' + name)
warn(msg)
except (psutil.NoSuchProcess, psutil.AccessDenied) as err:
self.assertEqual(err.pid, p.pid)
if err.name:
# make sure exception's name attr is set
# with the actual process name
self.assertEqual(err.name, p.name())
assert str(err)
assert err.msg
except Exception as err:
s = '\n' + '=' * 70 + '\n'
s += "FAIL: test_%s (proc=%s" % (name, p)
if ret != default:
s += ", ret=%s)" % repr(ret)
s += ')\n'
s += '-' * 70
s += "\n%s" % traceback.format_exc()
s = "\n".join((" " * 4) + i for i in s.splitlines())
s += '\n'
failures.append(s)
break
else:
if ret not in (0, 0.0, [], None, '', {}):
assert ret, ret
meth = getattr(self, name)
meth(ret, p)
if failures:
self.fail(''.join(failures))
# we should always have a non-empty list, not including PID 0 etc.
# special cases.
assert valid_procs
开发者ID:jomann09,项目名称:psutil,代码行数:71,代码来源:test_contracts.py
注:本文中的psutil._compat.callable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论