cpu满载,根据时间结束

from multiprocessing import Process
LOCK = True


def dead_loop():
    while LOCK:
        pass


def start_loop_thread():
    global LOCK
    print(LOCK)
    thread = threading.Thread(target=dead_loop)
    thread.setDaemon = True
    thread.start()
    time.sleep(5)
    LOCK = False
    print(LOCK)


def cpu_full_load():
    process_list = []
    for i in range(10):
        p = Process(target=start_loop_thread)
        p.start()
        process_list.append(p)

    for i in process_list:
        i.join()
    print('所有结束')


if __name__ =='__main__':
    cpu_full_load()
process_list = []


def dead_loop():
    while True:
        pass


def start_cpu_full_load():
    print('---start_cpu_full_load---')
    for i in range(10):
        p = Process(target=dead_loop)
        p.start()
        process_list.append(p)
    print('-' * 50)


def stop_cpu_full_load():
    print('---stop_cpu_full_load---')
    for i in process_list:
        i.kill()
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐