Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 同步期货>;在命令行中运行良好,而不是在使用pyinstaller或py2exe编译时_Python_Multiprocessing_Py2exe_Pyinstaller_Concurrent.futures - Fatal编程技术网

Python 同步期货>;在命令行中运行良好,而不是在使用pyinstaller或py2exe编译时

Python 同步期货>;在命令行中运行良好,而不是在使用pyinstaller或py2exe编译时,python,multiprocessing,py2exe,pyinstaller,concurrent.futures,Python,Multiprocessing,Py2exe,Pyinstaller,Concurrent.futures,我有一个基于concurrent.futures的非常简单的脚本,它在命令行(Python2.7)中运行良好,但在使用py2exe或Pyinstaller编译时崩溃(编译后的程序会打开越来越多的进程,如果我不先全部关闭它们,最终会完全阻塞窗口) 代码非常标准/简单,因此我很难理解此问题的根源。。。以前有人经历过吗?(我发现讨论涉及到一个类似的多处理问题……但没有什么可以用来解决我的问题) 致以最良好的祝愿, 我在Python 3.4中遇到了这个问题。在谷歌搜索了一段时间后,我发现了这个bug报告

我有一个基于concurrent.futures的非常简单的脚本,它在命令行(Python2.7)中运行良好,但在使用py2exe或Pyinstaller编译时崩溃(编译后的程序会打开越来越多的进程,如果我不先全部关闭它们,最终会完全阻塞窗口)

代码非常标准/简单,因此我很难理解此问题的根源。。。以前有人经历过吗?(我发现讨论涉及到一个类似的多处理问题……但没有什么可以用来解决我的问题)

致以最良好的祝愿,
我在Python 3.4中遇到了这个问题。在谷歌搜索了一段时间后,我发现了这个bug报告:

这让我看到了下面的文档,在我的应用程序中,它似乎解决了这个问题

Python 2.7的建议解决方案,直接来自文档:


不确定这是否会修复您正在使用的py2exe或Pyinstaller的问题,但我想我会发布以防万一。

补充rdp的答案,该答案从多处理文档中获得关于以下方面的提示:

您需要做的是在应用程序执行的最开始添加以下行:

来自多处理导入冻结支持的

如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
冻结支持()
从文档中也可以看到:

需要在主模块的
行之后直接调用此函数

在我的测试中,我发现我需要将它们添加到主应用程序模块,而不是使用
concurrent.futures
的模块,这意味着当进程分叉时,将再次启动可执行文件,并在执行恢复到池之前运行模块。这在我的例子中特别重要,PyQt应用程序将尝试启动一个新的GUI


作为旁注,中的错误报告表明,
运行时错误
可能没有被提出,这就是我的情况。

我使用的是python 3.6+

# -*- coding: utf8 -*-
import os
import socket
import concurrent.futures
from multiprocessing import freeze_support

def simple_checkDomain(aDomain):
    print aDomain 
    # Do other stuff

def main():

    with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
        for domain in ["google.com","yahoo.com"]:
            job = executor.submit(simple_checkDomain, domain)

if __name__ == "__main__":
    freeze_support()
    main()

它将解决这个问题。我正在测试的过程中,你添加了你的答案:)@dano-谢谢。抱歉抢走了你的风头。
# -*- coding: utf8 -*-
import os
import socket
import concurrent.futures
from multiprocessing import freeze_support

def simple_checkDomain(aDomain):
    print aDomain 
    # Do other stuff

def main():

    with concurrent.futures.ProcessPoolExecutor(max_workers=4) as executor:
        for domain in ["google.com","yahoo.com"]:
            job = executor.submit(simple_checkDomain, domain)

if __name__ == "__main__":
    freeze_support()
    main()