import psutil
import os
import threading
import time

def allocate_memory(target_fraction=0.25):
    """Allocate ~target_fraction of system RAM."""
    total_mem = psutil.virtual_memory().total
    target_size = int(total_mem * target_fraction)
    print(f"Allocating {target_size / (1024**3):.2f} GB (~{target_fraction*100:.0f}% of RAM)")
    try:
        block = bytearray(target_size)
        print("Memory successfully allocated.")
        return block
    except MemoryError:
        print("Not enough memory to allocate.")
        return None

def cpu_worker():
    """Keep CPU core busy with math operations."""
    while True:
        x = 0
        for i in range(10000000):
            x += i*i

if __name__ == "__main__":
    # Allocate memory
    mem_block = allocate_memory(0.25)