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.')
其实一行命令也可以:
python3 -c "a=' '*字节大小;input()"
比如占用1G内存:
python3 -c "a=' '*1024**3;input()"

浙公网安备 33010602011771号