#!/usr/bin/env python3 import resource TARGET_AS = 512 * 1024 * 1024 soft, hard = resource.getrlimit(resource.RLIMIT_AS) if hard != resource.RLIM_INFINITY and TARGET_AS > hard: raise RuntimeError( f"Hard limit too low for {TARGET_AS} bytes: {hard}" ) if soft != resource.RLIM_INFINITY and soft < TARGET_AS: resource.setrlimit(resource.RLIMIT_AS, (TARGET_AS, hard)) # Import or allocate after the limit check or raise. data = bytearray(300 * 1024 * 1024) print(f"allocated_bytes={len(data)}")