我在使用 py2app(对于 OS X)构建我的 PySide Python 应用程序时遇到问题。应用程序包上的线程似乎发生了一些有趣的事情。
这是最小的例子
from PySide.QtCore import *
from PySide.QtGui import *
import sys
class App(QApplication):
def __init__(self):
QApplication.__init__(self, sys.argv, True)
self.timer = QTimer(self)
if __name__=='__main__':
app = App()
app.exec_()
从命令行运行时:python test.py
,这可以正常工作而不会出错。但是,当我使用以下 setup.py 编译它时:
from setuptools import setup
import py2app
import PySide
APP = ['test.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': False,
'includes' : 'PySide',
'resources' : "qt_menu.nib"
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
这些错误出现在控制台中:
11/05/2013 13:54:20.958 [0x0-0xb37b37].org.pythonmac.unspecified.test: QObject: Cannot create children for a parent that is in a different thread.
11/05/2013 13:54:20.958 [0x0-0xb37b37].org.pythonmac.unspecified.test: (Parent is App(0x105f41f10), parent's thread is QThread(0x100106cc0), current thread is QThread(0x10251ea80)
因此,似乎 App 不再被构造为生活在主线程中。任何想法如何解决这一问题?