Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【可能的Bug】打包用到multiprocessing库的程序打包后无限循环 #23

Closed
fanweiya opened this issue Sep 23, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@fanweiya
Copy link

我在程序用到了多进程处理,然后用到了multiprocessing库,pyinstaller 打包时在主函数头部加multiprocessing.freeze_support()可以解决,用qpt打包的程序用这种方法还是不能解决,还是会无限循环

@fanweiya fanweiya added the bug Something isn't working label Sep 23, 2021
@GT-ZhangAcer
Copy link
Member

提供一下其他信息和一个可以复现的代码哈

@fanweiya
Copy link
Author

fanweiya commented Sep 23, 2021

提供一下其他信息和一个可以复现的代码哈

我写了一个简单的demo,正常情况他会几次print("origin",origin,"save",save),但是这个打包后一直弹窗,你可以试一下
我是win10系统

import multiprocessing
import os
import threading
import tkinter.filedialog
from multiprocessing import Pool, Process,freeze_support
import threading
from threading import Thread
class MyProcess(Process):
    def __init__(self,func,args):
        super().__init__()
        self.func=func
        self.args=args
    def run(self):
        self.func(*self.args)
def printfilename(origin,save):
    print("origin",origin,"save",save)
if __name__ == '__main__':
    multiprocessing.freeze_support()
    originpath=tkinter.filedialog.askdirectory(title="请选择要处理的文件夹路径")
    savepath=tkinter.filedialog.askdirectory(title="请选择保存路径")
    intnum=int(input("输入一个数字"))
    for i in range(intnum):
        testpool = MyProcess(printfilename, (originpath,savepath))
        testpool.start()

@GT-ZhangAcer
Copy link
Member

好,周末我到家看一下哈,现在手头没Windows机器了

@fanweiya
Copy link
Author

好,周末我到家看一下哈,现在手头没Windows机器了

嗯嗯,好的,谢谢

@GT-ZhangAcer
Copy link
Member

GT-ZhangAcer commented Sep 23, 2021

刚思考了一下,猜测大概率是由于打包后if __name__ == '__main__':语句被替换了,从而不能保护多进程程序的执行(这部分也有Windows的一部分原因,不支持fork)。
我先记录一下,后续测看看猜测是否成立。如果成立,大概率周末更新了

@GT-ZhangAcer
Copy link
Member

GT-ZhangAcer commented Oct 7, 2021

新版本1.0b1.dev6修复完毕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants