本文整理匯總了Python中psutil.RLIMIT_NOFILE屬性的典型用法代碼示例。如果您正苦於以下問題:Python psutil.RLIMIT_NOFILE屬性的具體用法?Python psutil.RLIMIT_NOFILE怎麽用?Python psutil.RLIMIT_NOFILE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類psutil
的用法示例。
在下文中一共展示了psutil.RLIMIT_NOFILE屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_linux_rlimit
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_linux_rlimit(self):
ae = self.assertEqual
hasit = LINUX and get_kernel_version() >= (2, 6, 36)
ae(hasattr(psutil.Process, "rlimit"), hasit)
ae(hasattr(psutil, "RLIM_INFINITY"), hasit)
ae(hasattr(psutil, "RLIMIT_AS"), hasit)
ae(hasattr(psutil, "RLIMIT_CORE"), hasit)
ae(hasattr(psutil, "RLIMIT_CPU"), hasit)
ae(hasattr(psutil, "RLIMIT_DATA"), hasit)
ae(hasattr(psutil, "RLIMIT_FSIZE"), hasit)
ae(hasattr(psutil, "RLIMIT_LOCKS"), hasit)
ae(hasattr(psutil, "RLIMIT_MEMLOCK"), hasit)
ae(hasattr(psutil, "RLIMIT_NOFILE"), hasit)
ae(hasattr(psutil, "RLIMIT_NPROC"), hasit)
ae(hasattr(psutil, "RLIMIT_RSS"), hasit)
ae(hasattr(psutil, "RLIMIT_STACK"), hasit)
hasit = LINUX and get_kernel_version() >= (3, 0)
ae(hasattr(psutil, "RLIMIT_MSGQUEUE"), hasit)
ae(hasattr(psutil, "RLIMIT_NICE"), hasit)
ae(hasattr(psutil, "RLIMIT_RTPRIO"), hasit)
ae(hasattr(psutil, "RLIMIT_RTTIME"), hasit)
ae(hasattr(psutil, "RLIMIT_SIGPENDING"), hasit)
示例2: get_process_limits
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def get_process_limits(self, pid):
p = psutil.Process(pid)
return {
'RLIMIT_AS': p.rlimit(psutil.RLIMIT_AS),
'RLIMIT_CORE': p.rlimit(psutil.RLIMIT_CORE),
'RLIMIT_CPU': p.rlimit(psutil.RLIMIT_CPU),
'RLIMIT_DATA': p.rlimit(psutil.RLIMIT_DATA),
'RLIMIT_FSIZE': p.rlimit(psutil.RLIMIT_FSIZE),
'RLIMIT_LOCKS': p.rlimit(psutil.RLIMIT_LOCKS),
'RLIMIT_MEMLOCK': p.rlimit(psutil.RLIMIT_MEMLOCK),
'RLIMIT_MSGQUEUE': p.rlimit(psutil.RLIMIT_MSGQUEUE),
'RLIMIT_NICE': p.rlimit(psutil.RLIMIT_NICE),
'RLIMIT_NOFILE': p.rlimit(psutil.RLIMIT_NOFILE),
'RLIMIT_NPROC': p.rlimit(psutil.RLIMIT_NPROC),
'RLIMIT_RSS': p.rlimit(psutil.RLIMIT_RSS),
'RLIMIT_RTPRIO': p.rlimit(psutil.RLIMIT_RTPRIO),
'RLIMIT_RTTIME': p.rlimit(psutil.RLIMIT_RTTIME),
'RLIMIT_SIGPENDING': p.rlimit(psutil.RLIMIT_SIGPENDING),
'RLIMIT_STACK': p.rlimit(psutil.RLIMIT_STACK)
}
示例3: test_rlimit_get
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_rlimit_get(self):
self.execute(self.proc.rlimit, psutil.RLIMIT_NOFILE)
示例4: test_rlimit_set
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_rlimit_set(self):
limit = thisproc.rlimit(psutil.RLIMIT_NOFILE)
self.execute(self.proc.rlimit, psutil.RLIMIT_NOFILE, limit)
self.execute_w_exc(OSError, self.proc.rlimit, -1)
示例5: test_rlimit_set
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_rlimit_set(self):
sproc = get_test_subprocess()
p = psutil.Process(sproc.pid)
p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))
self.assertEqual(p.rlimit(psutil.RLIMIT_NOFILE), (5, 5))
# If pid is 0 prlimit() applies to the calling process and
# we don't want that.
with self.assertRaises(ValueError):
psutil._psplatform.Process(0).rlimit(0)
with self.assertRaises(ValueError):
p.rlimit(psutil.RLIMIT_NOFILE, (5, 5, 5))
示例6: test_num_fds
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_num_fds(self):
# Note: this fails from time to time; I'm keen on thinking
# it doesn't mean something is broken
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
p = psutil.Process(os.getpid())
failures = []
ignored_names = ['terminate', 'kill', 'suspend', 'resume', 'nice',
'send_signal', 'wait', 'children', 'as_dict',
'memory_info_ex']
if LINUX and get_kernel_version() < (2, 6, 36):
ignored_names.append('rlimit')
if LINUX and get_kernel_version() < (2, 6, 23):
ignored_names.append('num_ctx_switches')
for name in dir(psutil.Process):
if (name.startswith('_') or name in ignored_names):
continue
else:
try:
num1 = p.num_fds()
for x in range(2):
call(p, name)
num2 = p.num_fds()
except psutil.AccessDenied:
pass
else:
if abs(num2 - num1) > 1:
fail = "failure while processing Process.%s method " \
"(before=%s, after=%s)" % (name, num1, num2)
failures.append(fail)
if failures:
self.fail('\n' + '\n'.join(failures))
示例7: test_rlimit_set
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_rlimit_set(self):
p = self.spawn_psproc()
p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))
self.assertEqual(p.rlimit(psutil.RLIMIT_NOFILE), (5, 5))
# If pid is 0 prlimit() applies to the calling process and
# we don't want that.
with self.assertRaises(ValueError):
psutil._psplatform.Process(0).rlimit(0)
with self.assertRaises(ValueError):
p.rlimit(psutil.RLIMIT_NOFILE, (5, 5, 5))
示例8: test_rlimit
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_rlimit(self):
self.execute(lambda: self.proc.rlimit(psutil.RLIMIT_NOFILE))
示例9: test_rlimit_set
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_rlimit_set(self):
limit = thisproc.rlimit(psutil.RLIMIT_NOFILE)
self.execute(lambda: self.proc.rlimit(psutil.RLIMIT_NOFILE, limit))
self.execute_w_exc(OSError, lambda: self.proc.rlimit(-1))
示例10: test_rlimit_zombie
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def test_rlimit_zombie(self):
# Emulate a case where rlimit() raises ENOSYS, which may
# happen in case of zombie process:
# https://travis-ci.org/giampaolo/psutil/jobs/51368273
with mock.patch("psutil._pslinux.cext.linux_prlimit",
side_effect=OSError(errno.ENOSYS, "")) as m:
p = psutil.Process()
p.name()
with self.assertRaises(psutil.ZombieProcess) as exc:
p.rlimit(psutil.RLIMIT_NOFILE)
assert m.called
self.assertEqual(exc.exception.pid, p.pid)
self.assertEqual(exc.exception.name, p.name())
示例11: _collect_max_file_descriptor_count
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def _collect_max_file_descriptor_count(self, psutil_stats, probe_name, process):
return process.rlimit(psutil.RLIMIT_NOFILE)[1]
示例12: getStats
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def getStats(self):
"""
Returns a dictionary containing the server stats and cpu/memory utilization
"""
# cpu
if not self.process:
return {}
t = os.times()
cpu_user, cpu_system = 0, 0
delta_t = t[-1]-self._last_t
if self._last_t and delta_t > 0:
cpu_user = (t[0]-self._last_cpu_u)*100./delta_t
cpu_system = (t[1]-self._last_cpu_s)*100./delta_t
self._last_cpu_u, self._last_cpu_s, self._last_t = t[0], t[1], t[-1]
# memory
m = self.process.get_memory_info()
d = dict(
cpu_percent=cpu_user+cpu_system,
cpu_user_percent=cpu_user,
cpu_system_percent=cpu_system,
memory_percent=self.process.get_memory_percent(),
memory_rss=m.rss,
memory_vms=m.vms,
#open_files=self.process.get_num_fds(),
#open_files_max=self.process.get_rlimit(psutil.RLIMIT_NOFILE)[1],
threads=self.process.get_num_threads(),
connections=self.process.get_connections().__len__(),
)
# temp
if self._calc_temp:
try:
d['temp'] = Popen(['/usr/bin/acpi', '-t'], stdout=PIPE).communicate()[0]
except Exception:
pass
# disk
if self._directory:
usage = psutil.disk_usage(self._directory)
d['disk_usage'] = usage.percent
d['disk_used'] = usage.used
return d
示例13: getProcessResourceUsage
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import RLIMIT_NOFILE [as 別名]
def getProcessResourceUsage(self, pid_list):
try:
results = {}
for pid in pid_list:
if pid == 0:
continue
result = {}
results[str(pid)] = result
try:
proc = psutil.Process(pid)
except psutil.NoSuchProcess as e:
LOG.info("No such process: %s", e.msg)
continue
except:
LOG.exception("Process %s:", pid)
continue
result["fileno"] = proc.num_fds()
try:
proc.rlimit
except AttributeError:
max_fileno = -1
max_vmsize = -1
else:
max_fileno = proc.rlimit(psutil.RLIMIT_NOFILE)[0]
max_vmsize = proc.rlimit(psutil.RLIMIT_AS)[0]
if max_fileno != -1:
result["max_fileno"] = max_fileno
result["numconnections"] = len(proc.connections('all'))
result["numfiles"] = len(proc.open_files())
if max_vmsize != -1:
result["max_vmsize"] = str(max_vmsize)
result["vmsize"] = str(proc.memory_info()[1])
result["numchildren"] = len(proc.children())
result["numthreads"] = proc.num_threads()
result["cpu"] = ",".join(str(x) for x in
[time.time()] +
list(proc.cpu_times()))
result["diskio"] = ",".join(str(x) for x in
[time.time()] +
list(proc.io_counters()))
return results
except:
LOG.exception("Error")
return {}