multiprocessing problem [pyqt, py2exe]

大憨熊 提交于 2019-11-28 08:22:51

I think your actual problem has to do with this:

The program works as expected under the python intepreter, i.e. if it is started from the command line "python myapp.py".

However, after I package the program using py2exe, every time when I click that button, > instead of starting the background task, a copy of the main window pops up.

You need to add a special call to the freeze_support() function to make the multiprocessing module work with "frozen" executables (eg, those made with py2exe):

if __name__ == "__main__":
    # add freeze support
    processing.freeze_support()
    a = QApplication(sys.argv)
    QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
    w = MainWindow()
    w.show()
    a.exec_()

Reference: http://docs.python.org/library/multiprocessing.html#multiprocessing.freeze_support

"Functionality within this package requires that the main method be importable by the children."

I think this means you have to have main() function defined somewhere.

The question is concerning Python 2 and was solved. For Python 3, it would look like:

from multiprocessing import freeze_support

if __name__ == '__main__':
    freeze_support()

    a = QApplication(sys.argv)
    ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!