python多处理模块导致无限循环
我试图使用多处理池来加速我的读/写功能。但是,当我尝试使用pyinstaller并使用exe运行它时。这个 结果是一个新进程生成一个新进程,该进程生成一个 新进程无限长,直到我注销,操作系统被强制关闭 终止我的所有用户进程。我不知道发生了什么事 在pycharm中运行时,甚至在运行.py时运行代码都没有问题 版本是python 3.6.3 平台:Windows7 代码如下所示:python多处理模块导致无限循环,python,multiprocessing,Python,Multiprocessing,我试图使用多处理池来加速我的读/写功能。但是,当我尝试使用pyinstaller并使用exe运行它时。这个 结果是一个新进程生成一个新进程,该进程生成一个 新进程无限长,直到我注销,操作系统被强制关闭 终止我的所有用户进程。我不知道发生了什么事 在pycharm中运行时,甚至在运行.py时运行代码都没有问题 版本是python 3.6.3 平台:Windows7 代码如下所示: if __name__ == "__main__": pool = Pool(2) pool.map(
if __name__ == "__main__":
pool = Pool(2)
pool.map(readwritevalue, [file for file in gettxtpath()])
pool.close()
pool.join()
GetFormated() ##Get the Final output of .csv
Getxlsx() ##Get the Report.xls
GetDocx() ##Get the docx format
t1 = time.time()
print("Parallel time{t}s".format(t=time.time() - t1))
你能帮我解释一下吗?
我搜索了谷歌,一些答案是将多处理模块放在“\uuuuu name\uuuuu==”\uuuuuu main\uuuu
”下,但是,我已经这样做了。那么,还有什么会导致进程无限膨胀呢
非常感谢。谢谢米兰韦尔比帮我找到答案 我把答案贴在这里。 导入多处理并使用pyinstaller时,只需添加一行即可
from multiprocessing import Pool,freeze_support
if __name__ == "__main__":
##Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable. (Has been tested with py2exe, PyInstaller and cx_Freeze.)
#One needs to call this function straight after the '__main__' line of the main module.
freeze_support()
t1 = time.time()
pool = Pool(2)
pool.map(readwritevalue, [file for file in gettxtpath()])
pool.close()
pool.join()
GetFormated() ##Get the Final output of Xunjian-Report.csv
Getxlsx() ##Get the Xunjian-Report.xls
GetDocx() ##Get the docx format
print("Cost time {t}".format(t=time.time() - t1))
你退房了吗?显然pyinstaller在多处理模块方面存在一些问题。@MilanVelebit非常感谢!它解决了我的问题!我不会因为这个解决方案而受到表扬,但请在下面用修改过的代码发布答案,以防其他人无意中发现,很高兴它有帮助@MilanVelebit我已经发布了答案。再次感谢您的大力帮助!