Seg Fault 11 when calling PySide using "run" command #1124

nonhermitian opened this Issue Dec 8, 2011 · 14 comments

3 participants


I am using iPython 0.11 to call a GUI about box written using PySide. Calling the GUI from inside iPython via

from qutip import * #my package
about() #about box

gives the correct result, i.e. opens the about window. However, running the exact same commands listed above inside a script file via


results in seg fault 11. Curiously, running

In[1]: from qutip import *


In[3]: run

works just fine.

I am running iPython version 0.11 with Python 2.7.2, both installed using MacPorts, on Mac OSX 10.7.2. The current PySide version is 1.0.9. The relevant portion of the crash report generated is given below.



Process: Python [21647]
Path: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/
Identifier: Python
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: bash [21642]

Date/Time: 2011-12-08 16:20:04.623 +0900
OS Version: Mac OS X Server 10.7.2 (11C74)
Report Version: 9

Interval Since Last Report: 1676458 sec
Crashes Since Last Report: 54
Per-App Crashes Since Last Report: 31
Anonymous UUID: 7E473779-A3A4-441E-9864-390BB3EF8800

Crashed Thread: 0 Dispatch queue:

Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000

VM Regions Near 0:
__TEXT 00000001071d1000-00000001071d2000 [ 4K] r-x/rwx SM=COW /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/

Application Specific Information:
objc[21647]: garbage collection is OFF

Thread 0 Crashed:: Dispatch queue:
0 libsystem_c.dylib 0x00007fff880924f0 strlen + 16
1 libsystem_c.dylib 0x00007fff8802e34b strdup + 18
2 libshiboken-python2.7.1.0.dylib 0x0000000109147ed7 Shiboken::sequenceToArgcArgv(_object, int, char**, char const) + 391
3 0x000000010b102b65 Sbk_QApplication_Init + 725
4 org.python.python 0x0000000107232b9a type_call + 362
5 org.python.python 0x00000001071e0fd1 PyObject_Call + 97
6 org.python.python 0x00000001072744cf PyEval_EvalFrameEx + 7871
7 org.python.python 0x000000010727a343 fast_function + 195
8 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
9 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
10 org.python.python 0x0000000107271d16 PyEval_EvalCode + 54
11 org.python.python 0x0000000107299b4e PyRun_FileExFlags + 174
12 org.python.python 0x000000010726df9a builtin_execfile + 490
13 org.python.python 0x0000000107274bfa PyEval_EvalFrameEx + 9706
14 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
15 org.python.python 0x000000010727a3b9 fast_function + 313
16 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
17 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
18 org.python.python 0x000000010727a3b9 fast_function + 313
19 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
20 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
21 org.python.python 0x000000010727a3b9 fast_function + 313
22 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
23 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
24 org.python.python 0x00000001072736cc PyEval_EvalFrameEx + 4284
25 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
26 org.python.python 0x000000010727a3b9 fast_function + 313
27 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
28 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
29 org.python.python 0x000000010727a3b9 fast_function + 313
30 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
31 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
32 org.python.python 0x000000010727a3b9 fast_function + 313
33 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
34 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
35 org.python.python 0x000000010727a3b9 fast_function + 313
36 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
37 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
38 org.python.python 0x000000010727a3b9 fast_function + 313
39 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
40 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
41 org.python.python 0x000000010727a3b9 fast_function + 313
42 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
43 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
44 org.python.python 0x000000010727a3b9 fast_function + 313
45 org.python.python 0x00000001072742be PyEval_EvalFrameEx + 7342
46 org.python.python 0x00000001072725b9 PyEval_EvalCodeEx + 2201
47 org.python.python 0x0000000107271d16 PyEval_EvalCode + 54
48 org.python.python 0x0000000107299b4e PyRun_FileExFlags + 174
49 org.python.python 0x0000000107299528 PyRun_SimpleFileExFlags + 424
50 org.python.python 0x00000001072ad63e Py_Main + 2990
51 org.python.python 0x00000001071d1f24 0x1071d1000 + 3876

IPython member

I'm not an expert on how the %run command works, but, if I understand correctly, is ran in it's own namespace, and then, some of the variable of this namespace are copied back into the IPython namespace. It seem to me that Qt/PySide will clean everything it i't not referenced. So the segfault appear on the copy back into the main namespace(?), except if it's already imported by from qutip import *.

look at #1001, and maybe some other issues , you can try %run -iwhich will run the program directly on IPython namespace, or %run -p not to copy back (I think it's -p, or is -p under the control of the debugger?). (see %run? for help, explanation and all options.)

Does it make sens ? (If anyone who understand this better than me can confirm or correct...)


Thank you for the quick reply. Sadly your recommendations did not alleviate the problem. I guess a little more care is needed when running GUI scripts than I thought. Also since I didn't attach a code snippet earlier, the code below will generate the mentioned problem.

import sys
from PySide import QtGui, QtCore

class AboutBox(QtGui.QWidget):
def init(self, parent=None):
QtGui.QWidget.init(self, parent)
self.setWindowTitle('About QuTiP')
self.resize(430, 450)
quit = QtGui.QPushButton('Close', self)
quit.setStyleSheet("QPushButton {font-family:Sans Serif;font-size: 14px;}")
quit.setGeometry((self.width()-80-10), 395, 80, 40)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)

app = QtGui.QApplication(sys.argv)
abox = AboutBox()

IPython member

I did not have segfault on master dev (but on mac), but it freeze when I click your button, not the close one in the menubar.
By changing the connect from app.quit to self.close quit.clicked.connect(self.close) it seem to work better, and does not hang.

I think quit()is auto called when exec_() return if quitOnLastWindowClosed is True(default value)

Still QApplication seem to be a singleton and I can't re-run it later...

I didin't know about raise_() i'll try to add it to the qtconsole which is always backgrounded when started.

IPython member

I'm a physicist too, and I don't think you'll find you'll find many people on this project whicht are not scientist before beeing programmers.

Is it working better now, or do you still have the issues ?
Note that you can try the dev version without having to install it. Just unzip, go inside and do python [usual options]

IPython member

This may well be a PySide bug which IPython is exposing. Have you tried to replicated it with PyQt?

In general, segfaults can't be (only) IPython's fault, because IPython is written in Python.


I just tried running a few test scripts using the full code:

and they all work nicely under the dev version. Thank you for all your help!!

IPython member

But then you can only pass sys.argv to the first invocation of run ... I would like to know if there is a proper way of quitting the app to launch one other later...

IPython member

I think we've ascertained that the original issue is either fixed or due to PySide, so I'll close this. Feel free to continue discussion, and open a new issue if you think there's anything IPython needs to do about %run and QApplications.

@takluyver takluyver closed this Dec 8, 2011
IPython member

@takluyver was right, it does work with PyQt4, not PySide, even in plain python shell works, but not with PySide instead of PyQt

example from link :

from PyQt4 import QtCore, QtGui #replace by PySide, it failed
import sys

app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
del app # force garbage collection of the first QApplication

app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()

I'll try to report the bug upstream, unless one of you have already an account, and want to do it...

IPython member

already exist,
marked as invalid...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment