python占用内存脚本(极简)

 

import sys


if len(sys.argv) <= 1 or {'-h', '--help'}.intersection(sys.argv):
    exit('usage: python3 occupy_mem.py memory_amount(unit: Byte)')

# Gradually occupy memory in 1GB increments to prevent untimely interruption when the consumption becomes too large .
mem_size = int(sys.argv[1])
unit = 1024 ** 3
mem_pool = [bytearray(unit)] * int(mem_size // unit) + [bytearray(mem_size % unit)]
input(f'{mem_size} Byte memory Occupied, press enter to end.')

 

posted @ 2025-11-29 17:35  小鱼圆又圆  阅读(1)  评论(0)    收藏  举报