打包前,在pycharm中直接运行,多进程也是一个窗口。打包后(pyinstaller、NSIS都试过),运行时出现多个窗口,增加的窗口数与进程数量一样,程序好像也不运行了。。。
怎么解决程序这个问题?因为必须有GUI来输入多进程操作的文件路径和进程数量,用的是pyqt5。
说明:涉及到部分内容,多线程实现不太方便,所以使用多进程。
主程序:
from test_tart import Ui_MainWindow
from PyQt5 import QtWidgets
import main_test
import sys
import time
class mywindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super(mywindow, self).__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.mains)
def mains(self):
path = self.lineEdit.text()
num = int(self.lineEdit_4.text())
t1 = float(time.time())
length = main_test.totest(path, num)
t2 = float(time.time())
t = str((t2-t1)/length)
self.lineEdit_2.setText(t)
# print((t2-t1)/length)
if __name__=="__main__":
app=QtWidgets.QApplication(sys.argv)
myshow=mywindow()
myshow.show()
sys.exit(app.exec_())
调用程序(多进程实现部分):
def totest(filepathtt, i):
# if __name__ == '__main__':
multiprocessing.freeze_support()
Data_filePath = os.listdir(filepathtt)
DfilePath = [filepathtt +'\\'+ x for x in Data_filePath]
# print(time.time())
with ProcessPool(processes= i) as pool:
pool.map(test, DfilePath)
# print(time.time())
return len(Data_filePath)