ejeschke / ginga

The Ginga astronomical FITS file viewer
BSD 3-Clause "New" or "Revised" License
122 stars 77 forks source link

Occasional seg fault on closing Ginga #103

Closed pllim closed 9 years ago

pllim commented 9 years ago

Using Ginga with my custom plugins (ginga -t pyside blahblahblah), I occasionally encounter segmentation fault when I close Ginga despite everything seemingly works. It is not unlike http://stackoverflow.com/questions/27721469/python-segmentation-fault-core-dumped . A quick search shows that your codes do call destroy() in several places. I wonder if that is indeed the cause. Below is my gdb traceback:

(gdb) where
#0  0x0000000d00000002 in ?? ()
#1  0x00007fffd9710102 in PySide::SignalManager::SignalManagerPrivate::~SignalManagerPrivate() ()
   from /my/path/lib/libpyside-python2.7.so.1.2
#2  0x00007fffd970df86 in PySide::SignalManager::clear() ()
   from /my/path/lib/libpyside-python2.7.so.1.2
#3  0x00007fffd971d000 in PySide::destroyQCoreApplication() ()
   from /my/path/lib/libpyside-python2.7.so.1.2
#4  0x00007fffd971d1c5 in PySide::runCleanupFunctions() ()
   from /my/path/lib/libpyside-python2.7.so.1.2
#5  0x00007fffd9a98b1d in SbkQtCoreModule___moduleShutdown(_object*) ()
   from /my/path/lib/python2.7/site-packages/PySide/QtCore.so
#6  0x00007ffff7d1322f in ext_do_call (f=<value optimized out>, 
    throwflag=<value optimized out>) at Python/ceval.c:4343
#7  PyEval_EvalFrameEx (f=<value optimized out>, 
    throwflag=<value optimized out>) at Python/ceval.c:2718
#8  0x00007ffff7d14c6e in PyEval_EvalCodeEx (co=0x7fffeabc6cb0, 
    globals=<value optimized out>, locals=<value optimized out>, 
    args=<value optimized out>, argcount=0, kws=0x0, kwcount=0, defs=0x0, 
    defcount=0, closure=0x0) at Python/ceval.c:3265
#9  0x00007ffff7c92851 in function_call (func=0x7fffeabccc08, arg=
    0x7ffff7bb9050, kw=0x0) at Objects/funcobject.c:526
#10 0x00007ffff7c63323 in PyObject_Call (func=0x7fffeabccc08, 
    arg=<value optimized out>, kw=<value optimized out>)
    at Objects/abstract.c:2529
#11 0x00007ffff7d0c823 in PyEval_CallObjectWithKeywords (func=0x7fffeabccc08, 
    arg=0x7ffff7bb9050, kw=<value optimized out>) at Python/ceval.c:3902
#12 0x00007ffff7d33c7a in call_sys_exitfunc () at Python/pythonrun.c:1751
#13 Py_Finalize () at Python/pythonrun.c:424
#14 0x00007ffff7d33e18 in Py_Exit (sts=0) at Python/pythonrun.c:1778
#15 0x00007ffff7d33f61 in handle_system_exit () at Python/pythonrun.c:1152
#16 0x00007ffff7d341ed in PyErr_PrintEx (set_sys_last_vars=1)
    at Python/pythonrun.c:1162
#17 0x00007ffff7d34ebe in PyRun_SimpleFileExFlags (fp=<value optimized out>, 
    filename=<value optimized out>, closeit=<value optimized out>, flags=
    0x7fffffffdab0) at Python/pythonrun.c:953
#18 0x00007ffff7d4a664 in Py_Main (argc=<value optimized out>, 
    argv=<value optimized out>) at Modules/main.c:645
#19 0x00000030f001ed5d in __libc_start_main (main=0x400710 <main>, argc=3, 
    ubp_av=0x7fffffffdbd8, init=<value optimized out>, 
    fini=<value optimized out>, rtld_fini=<value optimized out>, stack_end=
    0x7fffffffdbc8) at libc-start.c:226
#20 0x0000000000400649 in _start ()

Have you encountered this? Maybe it is not your job to fix my custom plugins causing this, but regardless, I want to bring this up in case I am not the only one encountering this issue.

ejeschke commented 9 years ago

Hi @pllim, I've encountered it on the rare occasion. I assume that indeed it has something to do with the qt library and maybe python destructors being called incorrectly in some odd state. I have heard that it is better to do something like this:

obj.deleteLater()
obj = None

than to call obj.destroy(). Maybe we should try changing all existing calls to destroy() to use this technique? Could you try it and let me know if it makes a difference for the amount of segfaults you are getting? It happens so rarely for me I'm not sure I could be sure I had actually changed any behavior. If it works fine I'd be happy to merge a PR.

pllim commented 9 years ago

@ejeschke , do you use Qt or GTK?

pllim commented 9 years ago

By the way, deleteLater() does not help in my case. I'll see if adding it to my custom plugins help. Will keep you updated.

ejeschke commented 9 years ago

GInga-wise, I use Qt for some machines and Gtk on our observation control system. So both are getting used regularly.

pllim commented 9 years ago

Update: The seg fault went away when I switched toolkit from PySide to PyQt4. In doing that, I didn't have to add deleteLater() to my custom plugins. I was using your latest version on master.

I don't know if you wish to add a warning about seg fault when using Ginga with PySide. You may close this issue when you wish.

Thanks!

pllim commented 9 years ago

And just in case you are curious, both my PySide and PyQt4 versions are the latest available on Anaconda. Here is my conda list:

abstract-rendering        0.5.1                np19py27_0  
anaconda                  2.1.0                np19py27_0  
argcomplete               0.8.1                    py27_0  
astropy                   1.0.2                np19py27_0  
atom                      0.3.9                    py27_0  
backports.ssl-match-hostname 3.4.0.2                   <pip>
beautiful-soup            4.3.2                    py27_0  
beautifulsoup4            4.3.2                     <pip>
binstar                   0.7.1                    py27_0  
bitarray                  0.8.1                    py27_0  
blaze                     0.6.3                np19py27_0  
blz                       0.6.2                np19py27_0  
bokeh                     0.6.1                np19py27_0  
boto                      2.32.1                   py27_0  
cairo                     1.12.2                        2  
casuarius                 1.1                      py27_0  
cdecimal                  2.3                      py27_0  
cffi                      0.8.6                    py27_0  
chaco                     4.4.1                np19py27_0  
colorama                  0.3.1                    py27_0  
conda                     3.10.1                   py27_0  
conda-build               1.8.2                    py27_0  
conda-env                 2.1.4                    py27_0  
configobj                 5.0.6                    py27_0  
cryptography              0.5.4                    py27_0  
curl                      7.38.0                        0  
cython                    0.21                     py27_0  
cytoolz                   0.7.0                    py27_0  
datashape                 0.3.0                np19py27_1  
dateutil                  2.1                      py27_2  
decorator                 3.4.0                    py27_0  
docutils                  0.12                     py27_0  
dynd-python               0.6.5                np19py27_0  
enable                    4.3.0                np19py27_2  
enaml                     0.9.8                    py27_0  
flask                     0.10.1                   py27_1  
fontconfig                2.11.1                        3  
freetype                  2.5.2                         0  
future                    0.13.1                   py27_0  
futures                   2.1.6                    py27_0  
gevent                    1.0.1                    py27_0  
gevent-websocket          0.9.3                    py27_0  
ginga                     2.3.20150422073626           <pip>
greenlet                  0.4.4                    py27_0  
grin                      1.2.1                    py27_1  
h5py                      2.3.1                np19py27_0  
hdf5                      1.8.13                        0  
ipython                   2.2.0                    py27_0  
ipython-notebook          2.2.0                    py27_0  
ipython-qtconsole         2.2.0                    py27_0  
itsdangerous              0.24                     py27_0  
jdcal                     1.0                      py27_0  
jinja2                    2.7.3                    py27_1  
jpeg                      8d                            0  
kiwisolver                0.1.3                    py27_0  
lcms                      1.19                          0  
libdynd                   0.6.5                         0  
libffi                    3.0.13                        0  
libpng                    1.5.13                        1  
libsodium                 0.4.5                         0  
libtiff                   4.0.2                         1  
libxml2                   2.9.0                         0  
libxslt                   1.1.28                        0  
llvm                      3.3                           0  
llvmpy                    0.12.7                   py27_0  
lxml                      3.4.0                    py27_0  
markupsafe                0.23                     py27_0  
matplotlib                1.4.0                np19py27_0  
mock                      1.0.1                    py27_0  
mpi4py                    1.3                      py27_0  
mpich2                    1.4.1p1                       0  
multipledispatch          0.4.7                    py27_0  
networkx                  1.9.1                    py27_0  
nltk                      3.0.0                np19py27_0  
nose                      1.3.4                    py27_0  
numba                     0.14.0               np19py27_0  
numexpr                   2.3.1                np19py27_0  
numpy                     1.9.2                    py27_0  
numpydoc                  0.5                      py27_0  
openpyxl                  1.8.5                    py27_0  
openssl                   1.0.1k                        1  
pandas                    0.14.1               np19py27_0  
patsy                     0.3.0                np19py27_0  
pep8                      1.5.7                    py27_0  
pil                       1.1.7                    py27_1  
pip                       6.1.1                    py27_0  
pixman                    0.26.2                        0  
ply                       3.4                      py27_0  
psutil                    2.1.1                    py27_0  
py                        1.4.25                   py27_0  
py2cairo                  1.10.0                   py27_1  
pycosat                   0.6.1                    py27_0  
pycparser                 2.10                     py27_0  
pycrypto                  2.6.1                    py27_0  
pycurl                    7.19.5                   py27_1  
pyface                    4.4.0                    py27_0  
pyflakes                  0.8.1                    py27_0  
pygments                  2.0.2                    py27_0  
pyopenssl                 0.14                     py27_0  
pyparsing                 2.0.1                    py27_0  
pyqt                      4.11.3                   py27_1  
pyside                    1.2.1                    py27_1  
pytables                  3.1.1                np19py27_1  
pytest                    2.6.3                    py27_0  
python                    2.7.9                         2  
python-dateutil           1.5                       <pip>
pytz                      2014.7                   py27_0  
pyyaml                    3.11                     py27_0  
pyzmq                     14.3.1                   py27_0  
qt                        4.8.6                         1  
readline                  6.2                           2  
redis                     2.6.9                         0  
redis-py                  2.9.1                    py27_0  
requests                  2.6.0                    py27_0  
rope                      0.9.4                    py27_1  
runipy                    0.1.1                    py27_0  
scikit-image              0.10.1               np19py27_0  
scikit-learn              0.15.2               np19py27_0  
scipy                     0.15.1               np19py27_0  
setuptools                15.0                     py27_0  
shiboken                  1.2.1                    py27_0  
sip                       4.16.5                   py27_0  
six                       1.8.0                    py27_0  
sockjs-tornado            1.0.1                    py27_0  
sphinx                    1.2.3                    py27_0  
spyder                    2.3.1                    py27_0  
spyder-app                2.3.1                    py27_0  
sqlalchemy                0.9.7                    py27_0  
sqlite                    3.8.4.1                       1  
ssl_match_hostname        3.4.0.2                  py27_0  
statsmodels               0.5.0                np19py27_2  
sympy                     0.7.5                    py27_0  
system                    5.8                           2  
tables                    3.1.1                     <pip>
theano                    0.6.0                np19py27_0  
tk                        8.5.18                        0  
toolz                     0.7.0                    py27_0  
tornado                   4.0.2                    py27_0  
traits                    4.4.0                    py27_0  
traitsui                  4.4.0                    py27_0  
ujson                     1.33                     py27_0  
unicodecsv                0.9.4                    py27_0  
util-linux                2.21                          0  
werkzeug                  0.9.6                    py27_1  
wss-tools                 0.1.0.dev0                <pip>
xlrd                      0.9.3                    py27_0  
xlsxwriter                0.5.7                    py27_0  
xlwt                      0.7.5                    py27_0  
yaml                      0.1.4                         0  
zeromq                    4.0.4                         0  
zlib                      1.2.8                         0  
ejeschke commented 9 years ago

Thanks, @pllim, I haven't really tested all that much with PySide, so that may indeed be the issue. Some subtle termination race condition issue? In any case, good to hear your experience. I think most people are using with PyQt via anaconda or linux.