从线程运行多处理

时间:2015-03-20 07:23:04

标签: python multithreading multiprocessing

我可以从线程运行多处理吗?我问,因为我已经尝试了,并且它在Spyder中运行,但是,当创建EXE文件时,它确实很奇怪。

打开多个GUI等奇怪的事情。这是一段相关的代码:

class Ui_MainWindow(object):

    #class to handle GUI
    #at some point does this
    def startWorker(self):
        self.worker1= WorkerThread()
        self.worker1.start()

class WorkerThread(QtCore.QThread):
     #class to do long hard work without freezing GUI
     def __init__(self, parent=None):
         QtCore.QThread.__init__(self)
         super(WorkerThread, self).__init__(parent)

     def run(self):
         p1 = multiprocessing.Process(target=someTraget, args=someArgs)
         p2 = multiprocessing.Process(target=someTarget, args=someArgs)
         p1.daemon = True; p2.daemon = True
         p1.start();p2.start()

编辑:评论:

要创建EXE文件,我正在使用PyInstaller 2.1:

pyinstaller --onefile --windowed main.py

对我的主人的呼唤如下:

if __name__ == "__main__":

    multiprocessing.freeze_support()

    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.showMaximized()
    sys.exit(app.exec_())

0 个答案:

没有答案