[cx-freeze-users] With "concurrent.futures", cx_freeze relaunchs the application instead of the spe
Brought to you by:
atuining
From: Pham, H. <Hie...@te...> - 2012-04-20 19:39:52
|
Hello everyone, I am learning on how to use the "concurrent.futures" to execute multiple processes parallel. Using the example http://www-inst.eecs.berkeley.edu/~cs61a/sp12/lectures/lect35.py and combine it with the PyQt GUI. It run well and make use of the system with multiple processors. The problem is when it is compiled with cx_freeze, for each "is_prime" process is called, the complied application re-launch itself instead of execute the "is_prime" in a new process. I have been Google but did not find any solution. If you have any suggestion please let me know - Greatly appreciated. My system: Window XP SP3 python-3.2.3 pywin32-217.win32-py3.2 PyQt-Py3.2-x86-gpl-4.9.1-1 cx_Freeze-4.2.3.win32-py3.2 Source: import os import sys from PyQt4 import QtCore, QtGui ####################### # code below is example at http://www-inst.eecs.berkeley.edu/~cs61a/sp12/lectures/lect35.py import concurrent.futures import math PRIMES = [ 112272535095293, 112582705942171, 112272535095293, 115280095190773, 115797848077099, 1099726899285419] def is_prime(n): if n % 2 == 0: return False sqrt_n = int(math.floor(math.sqrt(n))) for i in range(3, sqrt_n + 1, 2): if n % i == 0: return False return True ################################ # Add on PyQt GUI class TrmIO(QtGui.QTextEdit): def __init__(self): super(TrmIO, self).__init__(None) def write(self, data): self.append(data) def read(self): pass class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.resize(900, 600) self.centralwidget = QtGui.QWidget(MainWindow) self.gridLayout = QtGui.QGridLayout(self.centralwidget) self.verticalLayout = QtGui.QVBoxLayout() self.ioTrm = TrmIO() self.verticalLayout.addWidget(self.ioTrm) self.horizontalLayout = QtGui.QHBoxLayout() spacerItem = QtGui.QSpacerItem(150, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) spacerItem1 = QtGui.QSpacerItem(100, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem1) self.toolButton_6 = QtGui.QToolButton(self.centralwidget) self.toolButton_6.setText("DONE") self.horizontalLayout.addWidget(self.toolButton_6) self.verticalLayout.addLayout(self.horizontalLayout) self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) MainWindow.setWindowTitle("speedyView") MainWindow.show() QtCore.QCoreApplication.processEvents() QtCore.QObject.connect(ui.toolButton_6, QtCore.SIGNAL("clicked()"), self.onDone) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.sendIOtoTrm() def onDone(self): sys.exit(0) def sendIOtoTrm(self): sys.stdin = sys.stdout = sys.stderr = self.ioTrm def startProcs(self): # code below is example at http://www-inst.eecs.berkeley.edu/~cs61a/sp12/lectures/lect35.py with concurrent.futures.ProcessPoolExecutor() as executor: for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)): print('%d is prime: %s' % (number, prime)) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) MainWindow = QtGui.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() ui.startProcs() sys.exit(app.exec_()) cx_freeze build script : import os import sys import shutil from cx_Freeze import setup, Executable os.environ['PYTHONCASEOK'] = '1' dest = '../Test_Build' PYTHON = 'C:/Python' paths = [os.path.join(PYTHON, 'Lib/site-packages/PyQt4'), ] packages = ['PyQt4'] includes = ['PyQt4'] SACU = Executable(script="PyQtPapallelProcs.py", base="Console", #base="Win32GUI", targetName = "MyAppl.exe", ) setup(name = "PyQtPapallelProcs", version = '1.0', description = "Test Concurrent Processes", options = {'build_exe': {'path': sys.path+paths, 'packages':packages, 'includes':includes, 'build_exe':dest, } }, executables = [SACU], ) shutil.copy(os.path.join(paths[0], 'libeay32.dll'), os.path.join(dest,'libeay32.dll')) shutil.copy(os.path.join(paths[0], 'ssleay32.dll'), os.path.join(dest,'ssleay32.dll')) # End of cx_freeze |