# author: xiaoyang
# date: 2025/09/28
import os
import sys
import time
from multiprocessing import Process
def ac_cpu(timeout=None):
    t0 = time.time()
    while timeout and time.time() - t0 < timeout:
        1024 ** 1024
if __name__ == '__main__':
    ratio = 0.5
    delay = 10 * 60
    if '-h' in sys.argv:
        exit('usage:\npython cpu_a.py [float] [float]\nsample:\npython cpu_a.py 0.5 60')
    else:
        if len(sys.argv) > 1:
            ratio = float(sys.argv[1])
        if len(sys.argv) > 2:
            delay = float(sys.argv[2])
    ac = int(os.cpu_count() * ratio)
    print(f'共{os.cpu_count()}核,占用{ac}核, 持续{delay}秒')
    ps = []
    for i in range(ac):
        p = Process(target=ac_cpu, kwargs={'timeout': delay}, daemon=True)
        ps.append(p)
        p.start()
    for p in ps:
        p.join()