本文整理匯總了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)