Skip to content

执行多进程相关代码,无限启动进程 #106

@roydad

Description

@roydad

执行多进程相关代码,无限启动进程, python环境为 3.11.5, 以下为PyStand.py内容:

if __name__ == "__main__":
    import multiprocessing as mp
    mp.set_start_method("spawn", force=True)
    mp.freeze_support()
    from concurrent.futures import ProcessPoolExecutor
    import os

    print("主进程 PID:", os.getpid())

    def worker(x):
        return x * x

    with ProcessPoolExecutor(4) as pool:
        print("结果:", list(pool.map(worker, range(20))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions