本文整理汇总了Python中resource.RLIMIT_CPU属性的典型用法代码示例。如果您正苦于以下问题:Python resource.RLIMIT_CPU属性的具体用法?Python resource.RLIMIT_CPU怎么用?Python resource.RLIMIT_CPU使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类resource
的用法示例。
在下文中一共展示了resource.RLIMIT_CPU属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: report_resource_limits
# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_CPU [as 别名]
def report_resource_limits(logger: logging.Logger) -> None:
resources = [
('CPU time (seconds)', resource.RLIMIT_CPU),
('Heap size (bytes)', resource.RLIMIT_DATA),
('Num. process', resource.RLIMIT_NPROC),
('Num. files', resource.RLIMIT_NOFILE),
('Address space', resource.RLIMIT_AS),
('Locked address space', resource.RLIMIT_MEMLOCK)
]
resource_limits = [
(name, resource.getrlimit(res)) for (name, res) in resources
]
resource_s = '\n'.join([
'* {}: {}'.format(res, lim) for (res, lim) in resource_limits
])
logger.info("resource limits:\n%s", indent(resource_s, 2))
示例2: limitedTime
# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_CPU [as 别名]
def limitedTime(second, func, *args, **kw):
second = fixTimeout(second)
old_alarm = signal(SIGXCPU, signalHandler)
current = getrlimit(RLIMIT_CPU)
try:
setrlimit(RLIMIT_CPU, (second, current[1]))
return func(*args, **kw)
finally:
setrlimit(RLIMIT_CPU, current)
signal(SIGXCPU, old_alarm)
示例3: test_cpu_time
# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_CPU [as 别名]
def test_cpu_time(self):
time = self.soft_limit(resource.RLIMIT_CPU, 1, 1024)
prlimit = processutils.ProcessLimits(cpu_time=time)
self.check_limit(prlimit, 'RLIMIT_CPU', prlimit.cpu_time)