5

I am having problems building my PySide Python app using py2app (for OS X). It appears that something funny happens with threads on the app bundle.

Here is the minimal example

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_()

When run from the command line: python test.py, this works fine without error. However when I then compile it with the following 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'],
)

these errors appear in the Console:

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)

So it appears that App is not being constructed to live in the main thread any more. Any ideas how to fix this?

Tim MB
  • 4,413
  • 4
  • 38
  • 48
  • For what it's worth, I can't reproduce your issue using PyQt4 (Qt-4.8.3, PyQt-4.9.5, OSX-10.7, Python-2.7.3, py2app-0.7.3). Perhaps this issue only affects PySide users? – Stuart Berg May 15 '13 at 19:00
  • That's odd. Py2app doesn't create threads in the application bundle. – Ronald Oussoren May 17 '13 at 10:41
  • BTW. You don't have to import Pyside in your setup.py file. – Ronald Oussoren May 17 '13 at 10:42
  • Thanks - it is strange. It might also be worth mentioning that I'm using MacPorts. I have a hunch that the issue may involve a dependency that has installed itself for both Python 3 and Python 2, although there's not much in the error messages to support that. – Tim MB May 21 '13 at 06:27
  • 1
    Yep, compiling on a friend's MacPorts setup doesn't have this problem - there must be something funny with my setup. – Tim MB Jun 05 '13 at 13:40

1 Answers1

0

The problem seems to be the way PySide manage the QThreads. Yo're creating a QTimer with a QApplication as parent. When using PyQt4 that's not as problem, but it might be on PySide.

A QTimer also spawns a QThread so, try run your code without creating the QTimer.

Note: At the time you asked the question, this could be a bug. And might be fixed in the last versions of PySide. (I'm just speculating :D)

Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60