python 中的 python 多处理库问题

问题描述 投票:0回答:1

我在 python 中的多处理库方面遇到问题。 库已安装。我对此很确定。

def foo():
    print("hello")

import multiprocessing as mp

task = mp.Process(target = foo)
task.start()

我期待程序打印“hello”,但退出什么也没有。

我通过pip卸载了这个库并再次安装,但结果没有改变

python multithreading multiprocessing python-multithreading
1个回答
1
投票

您忘记使用

task.join()
。如果没有 join(),主程序可能会在子进程有机会完成执行之前终止。

© www.soinside.com 2019 - 2024. All rights reserved.