简体   繁体   English

Windows 10上的Python多处理

[英]Python multiprocessing on Windows 10

I'm running some code on both a Windows 7 pc and a Windows 10 laptop: 我在Windows 7 PC和Windows 10笔记本电脑上都运行一些代码:

def project(filename):
    **Do Something Here**


if __name__ == '__main__':
    pool = Pool(processes=4)
    results = [pool.apply_async(project, args=(filename,)) for filename in filenamelist]
    output = [p.get() for p in results]
    print output

Both computers are dual core/4 threads, so they should both be fine running 4 processes. 两台计算机都是双核/ 4线程,因此它们应该都可以很好地运行4个进程。 The problem I have is that when I run the code on Windows 10 I get 4 python processes running, but they use 0% of the cpu and they will not output anything, unlike the Windows 7 pc which will run at full usage on all 4 threads and work perfectly. 我的问题是,当我在Windows 10上运行代码时,我运行了4个python进程,但是它们使用0%的cpu,并且它们不会输出任何内容,这与Windows 7 pc会在所有4个组件上完全使用线程和完美地工作。

The code works fine on the Windows 10 laptop if I don't use multiprocessing, so the problem must be related to that. 如果我不使用多处理程序,则该代码在Windows 10笔记本电脑上可以正常工作,因此问题必须与此相关。 Does multiprocessing with Python not work in Windows 10 yet? 使用Python进行的多处理是否还不能在Windows 10中使用? I am running Python 2.7 on both machines by the way. 顺便说一下,我在两台机器上都运行Python 2.7。

[Edit]: Windows 7 pc processor is an i5-650, Windows 10 laptop processor is an i3-2370M [编辑]:Windows 7 pc处理器是i5-650,Windows 10笔记本电脑处理器是i3-2370M

[Update]: I reverted the laptop back to Windows 8.1 and the exact same code runs as intended, this is definitely a Windows 10 issue. [更新]:我将笔记本电脑恢复为Windows 8.1,并且运行的代码完全符合预期,这绝对是Windows 10的问题。

[Edit]: The method I'm using to generate the filenamelist is as follows, however this works fine on Windows 7. [编辑]:我用来生成filenamelist的方法如下,但是在Windows 7上可以正常工作。

def get_unfinished_files(indir, outdir):
    filenamelist = []
    for filename in os.listdir(indir):
        if filename not in os.listdir(outdir) and filename.endswith('.png'):
            filenamelist.append(filename)
    return filenamelist

Had similar issue. 有类似的问题。 As I found, it was just a bug in python in my case: https://bugs.python.org/issue35797 正如我发现的那样,在我看来,这只是python中的一个错误: https//bugs.python.org/issue35797

It occurs when using multiprocessing through venv . 通过venv使用多处理时会发生这种情况。

Bugfix is released in Python 3.7.3. Bugfix在Python 3.7.3中发布。

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

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