相关疑难解决方法(0)

尝试python多处理的Windows上的RuntimeError

我正在尝试在Windows机器上使用线程和多处理的第一个正式的python程序.我无法启动进程,python提供以下消息.问题是,我没有在模块中启动我的线程.线程在类中的单独模块中处理.

编辑:顺便说一句,这个代码在ubuntu上正常运行.不是在窗户上

RuntimeError: 
            Attempt to start a new process before the current process
            has finished its bootstrapping phase.
            This probably means that you are on Windows and you have
            forgotten to use the proper idiom in the main module:
                if __name__ == '__main__':
                    freeze_support()
                    ...
            The "freeze_support()" line can be omitted if the program
            is not going to be frozen to produce a Windows executable.
Run Code Online (Sandbox Code Playgroud)

我的原始代码很长,但我能够在删节版本的代码中重现错误.它分为两个文件,第一个是主模块,除了导入处理进程/线程和调用方法的模块之外,它只做很少的事情.第二个模块是代码的核心所在.


testMain.py:

import parallelTestModule

extractor = parallelTestModule.ParallelExtractor()
extractor.runInParallel(numProcesses=2, numThreads=4)
Run Code Online (Sandbox Code Playgroud)

parallelTestModule.py:

import multiprocessing …
Run Code Online (Sandbox Code Playgroud)

python windows multiprocessing

79
推荐指数
5
解决办法
5万
查看次数

标签 统计

multiprocessing ×1

python ×1

windows ×1