PyStand
PyStand copied to clipboard
执行多进程相关代码,无限启动进程
执行多进程相关代码,无限启动进程, 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))))
if "runtime" in sys.exec_prefix: multiprocessing.set_executable(os.path.join(sys.exec_prefix, "pythonw.exe")),试试这个
https://github.com/skywind3000/PyStand/issues/21