简体   繁体   English

Python 多处理在 Visual Studio 中不起作用

[英]Python multiprocessing doesn't work in visual studio

I want to make something with the multiprocessing library.我想用multiprocessing库做点什么。 But when I run the following code in Visual Studio on my Windows PC, it won't stop the programming and it doesn't print anything.但是,当我在 Windows PC 上的 Visual Studio 中运行以下代码时,它不会停止编程,也不会打印任何内容。

import multiprocessing
import os

def test():
    print('Hello')

if __name__ == '__main__':
    p = multiprocessing.Process(target=test)
    p.start()
    p.join()

The code works if I don't have a loop at the first process如果我在第一个过程中没有循环,则代码有效

Agreed, it does not work with any example in VS 2019. This used to work 6 months ago.同意,它不适用于 VS 2019 中的任何示例。这曾经在 6 个月前有效。 I recommend just starting things with a batch script.我建议从批处理脚本开始。

If you run the your program without debugging (Ctrl + F5 or right click your program and "start without debugging"), the multiprocessing functions just fine.如果您在不调试的情况下运行程序(Ctrl + F5 或右键单击您的程序并“不调试就启动”),多处理功能就可以了。 I was having the same issue in VS 2019. My guess is multi-processing debugging isn't supported in VS (it isn't in VS code from this issue in 2017 https://github.com/Microsoft/vscode-python/issues/314 ).我在 VS 2019 中遇到了同样的问题。我的猜测是 VS 不支持多处理调试(它不在 2017 年此问题的 VS 代码中https://github.com/Microsoft/vscode-python/问题/314 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM