resource.setrlimit(type, (limit, hard_limit))
try:
    yield
finally:
    resource.setrlimit(type, (soft_limit, hard_limit))
with limit(100 * (1 << 20)):
    i = 1
while True:
    i <<= 1
Бесконечные целые числа Python