silx-kit / silx

silx toolkit
http://www.silx.org/doc/silx/latest/
MIT License
129 stars 73 forks source link

[silx view] Segmentation fault on close #849

Closed vallsv closed 6 years ago

vallsv commented 7 years ago

On my computer (Debian 8, Python 3), the application silx view often finish with a segmentation fault at the end of the execution. It would be nice to try to understand where does it come from.

valls@linkdick:~/workspace/pyfai.git$ silx view test_calibration/sample-jp/*.edf
Segmentation fault

It only seg fault when i close the application. Then it is not so critical.

dnaudet commented 7 years ago

Happens sometimes (unfortunately not the only case tho) when you try to use a QObject whose parent has been deleted.

e.g :

o1 = QObject()
o2 = QObject(o1)  # o1 takes ownership of o2
del o1
# o2 still exists in python, but try calling any of its methods and you will have a surprise
vasole commented 7 years ago

Sometimes to call QApplication deleteLater helps, but it is not warrantied.

vallsv commented 7 years ago
[New Thread 0x7ffff0b49700 (LWP 11510)]
[New Thread 0x7ffff0348700 (LWP 11511)]
[New Thread 0x7fffedb47700 (LWP 11512)]
[New Thread 0x7fffeb346700 (LWP 11513)]
[New Thread 0x7fffe8b45700 (LWP 11514)]
[New Thread 0x7fffe6344700 (LWP 11515)]
[New Thread 0x7fffe3b43700 (LWP 11516)]
[New Thread 0x7fffe1342700 (LWP 11517)]
[New Thread 0x7fffdeb41700 (LWP 11518)]
[New Thread 0x7fffdc340700 (LWP 11519)]
[New Thread 0x7fffd9b3f700 (LWP 11520)]
[New Thread 0x7fffbda6d700 (LWP 11521)]
[New Thread 0x7fffbd26c700 (LWP 11522)]
[Thread 0x7fffbd26c700 (LWP 11522) exited]
[Thread 0x7fffbda6d700 (LWP 11521) exited]

Program received signal SIGSEGV, Segmentation fault.
0x00007fffd0d3d3c9 in QMutex::lock() () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
(gdb) bt
#0  0x00007fffd0d3d3c9 in QMutex::lock() () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#1  0x00007fffd0e50609 in QCoreApplication::postEvent(QObject*, QEvent*, int) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#2  0x00007fffcffb49ac in ?? () from /usr/lib/python2.7/dist-packages/PyQt4/QtGui.so
#3  0x00007fffd1b770d6 in forgetObject (sw=sw@entry=0x7fffaca5c0e8) at /build/sip4-NAwNHZ/sip4-4.16.4+dfsg/siplib/siplib.c:11080
#4  0x00007fffd1b78559 in sipWrapper_dealloc (self=0x7fffaca5c0e8) at /build/sip4-NAwNHZ/sip4-4.16.4+dfsg/siplib/siplib.c:10632
#5  0x000000000050e386 in subtype_dealloc.lto_priv () at ../Objects/typeobject.c:1030
#6  0x00000000004a4920 in list_dealloc.lto_priv.2867 (op=0x7ffff6c23290) at ../Objects/listobject.c:309
#7  0x00000000004b7d0b in dict_dealloc.lto_priv.330 (mp=0x7fffaeba7280) at ../Objects/dictobject.c:1010
#8  0x00007fffd1b75197 in sipSimpleWrapper_clear (self=self@entry=0x7fffaec0d510) at /build/sip4-NAwNHZ/sip4-4.16.4+dfsg/siplib/siplib.c:10193
#9  0x00007fffd1b78474 in sipWrapper_clear (self=0x7fffaec0d510) at /build/sip4-NAwNHZ/sip4-4.16.4+dfsg/siplib/siplib.c:10591
#10 0x00000000004a6cf7 in subtype_clear (self=<Plot2D at remote 0x7fffaec0d510>) at ../Objects/typeobject.c:896
#11 delete_garbage (old=0x93c2e0 <generations.lto_priv+96>, collectable=0x7fffffffdc20) at ../Modules/gcmodule.c:820
#12 collect.lto_priv () at ../Modules/gcmodule.c:984
#13 0x0000000000515d00 in PyGC_Collect () at ../Modules/gcmodule.c:1440
#14 0x0000000000513c1f in Py_Finalize () at ../Python/pythonrun.c:449
#15 0x0000000000498099 in Py_Main () at ../Modules/main.c:665
#16 0x00007ffff6f12b45 in __libc_start_main (main=0x497c60 <main>, argc=4, argv=0x7fffffffded8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, 
    stack_end=0x7fffffffdec8) at libc-start.c:287
#17 0x0000000000497b8b in _start ()

It looks to be not very useful.

jcesardasilva commented 6 years ago

The segfault problem happens also to me and not only when the application closes, but the application does not even open. The SegFault happens immediately after typing the command "silx view ". It does not even matter the file format (edf, h5, tif, png ...). I am running it in Ubuntu 16.

vallsv commented 6 years ago

Hi Julio. You talk about a segfault on close? Or while using the application? I would prefer to open a new issue but it's fine.

Could you check with the last master? And which version of Python do you use? Which Qt binding do you use? And which version of Qt do you use? Could you try to send us a gdb backtrace or do you think we can try to connect and check things on your computer?

jcesardasilva commented 6 years ago

Hi Valentin, Maybe I should create a new issue, because the SegFault appears even before opening the applications. I've recently found out that it work well with python 2, but not with python 3. This is really weird. I did not check with last master, but I only did a pip3 install --upgrade silx. My python3 version is "Python 3.5.2", and python2 version is "Python 2.7.12". `jdasilva@gabor:~$ pip3 list --format=columns Package Version


absl-py 0.1.10
alabaster 0.7.10
aperture 0.1.14
appdirs 1.4.3
apptools 4.4.0
apt-xapian-index 0.47
apturl 0.5.2
asn1crypto 0.24.0
astroid 1.6.1
attrs 17.4.0
Babel 2.5.3
beautifulsoup4 4.6.0
bleach 2.1.2
blinker 1.4
Brlapi 0.6.4
cairocffi 0.8.0
certifi 2018.1.18
cffi 1.11.4
chardet 3.0.4
checkbox-support 0.37.0
cloudpickle 0.5.2
coloredlogs 9.0
command-not-found 0.3
configobj 5.0.6
cryptography 2.1.4
cycler 0.10.0
Cython 0.27.3
dask 0.17.1
decorator 4.1.2
defer 1.0.6
devscripts 1.0.0
docutils 0.14
entrypoints 0.2.3
enum34 1.1.6
fastcache 1.0.2
feedparser 5.2.1
fisx 1.1.4
futures 3.1.1
guacamole 0.9.2
h5py 2.7.1 hdf5plugin 1.4.0
html5lib 1.0.1
httplib2 0.10.3
humanfriendly 4.8
idna 2.6
imagej 0.1.1
imagesize 1.0.0
ipykernel 4.8.2
ipython 6.1.0
ipython-genutils 0.2.0
isort 4.3.4
jedi 0.11.1
Jinja2 2.10
joblib 0.11
jsonschema 2.6.0
jupyter-client 5.2.2
jupyter-core 4.4.0
Keras 2.1.4
language-selector 0.1
lazy-object-proxy 1.3.1
libtiff 0.4.2
llvmlite 0.22.0
louis 2.6.4
lxml 4.1.1
Mako 1.0.7
Markdown 2.6.11
MarkupSafe 1.0
matplotlib 2.1.2
mccabe 0.6.1
mistune 0.8.3
mpi4py 3.0.0
nbconvert 5.3.1
nbformat 4.4.0
networkx 2.1
nose 1.3.7
notebook 5.4.0
numba 0.37.0
numexpr 2.6.4
numpy 1.14.1
numpydoc 0.7.0
oauthlib 2.0.6
olefile 0.45.1
onboard 1.2.0
oneconf 0.3.9
opencv-python 3.4.0.12
opticspy 0.2.1
packaging 16.8
padme 1.1.1
pandas 0.22.0
pandocfilters 1.4.2
parso 0.1.1
pep8 1.7.1
pexpect 4.2.1
pickleshare 0.7.4
Pillow 5.0.0
pip 9.0.1
piston-mini-client 0.7.5
plainbox 0.38.0
pluggy 0.6.0
ply 3.11
prompt-toolkit 1.0.15
protobuf 3.5.1
psutil 5.4.3
ptyprocess 0.5.2
py 1.5.2
pyasn1 0.4.2
pycairo 1.16.2
pycodestyle 2.3.1
pycparser 2.18
pycrypto 2.6.1
pycups 1.9.73
pycurl 7.43.0.1
pyexpect 1.0.17
pyface 5.1.0
pyFFTW 0.10.4
pyflakes 1.6.0
pygame 1.9.3
Pygments 2.2.0
PyGObject 3.27.4
PyJWT 1.5.3
pylint 1.8.2
PyMca5 5.2.2
pympress 1.1.2
pyopencl 2018.1.1
PyOpenGL 3.1.0
pyparsing 2.2.0
PyQt5 5.9.2
pyserial 3.4
pytest 3.4.1
python-apt 1.1.0b1+ubuntu0.16.4.1 python-dateutil 2.6.1
python-debian 0.1.32
python-distutils-extra 2.39
python-systemd 231
python-vlc 3.0.102
pytools 2018.1
pytz 2018.3
PyWavelets 0.5.2
pyxdg 0.26
PyYAML 3.12
pyzernikemoment 0.0.2
pyzmq 17.0.0
QtAwesome 0.4.4
qtconsole 4.3.1
QtPy 1.3.1
rayopt 0.2
reportlab 3.4.0
requests 2.18.4
requests-unixsocket 0.1.5
roman 2.0.0
rope 0.10.7
rope-py3k 0.9.4.post1
scikit-image 0.13.1
scikit-video 1.1.10
scipy 1.0.0
screen-resolution-extra 0.0.0
seaborn 0.8.1
Send2Trash 1.5.0
sessioninstaller 0.0.0
setuptools 38.5.1
silx 0.6.1
SimpleCV 1.3
simplegeneric 0.8.1
sip 4.19.7
six 1.10.0
snowballstemmer 1.2.1
software-center-aptd-plugins 0.0.0
Sphinx 1.7.1
sphinx-rtd-theme 0.2.4
sphinxcontrib-websupport 1.0.1
spyder 3.2.7
SQLAlchemy 1.2.4
ssh-import-id 5.6
system-service 0.3
tables 3.4.2
tensorflow 1.5.0
tensorflow-tensorboard 1.5.1
terminado 0.8.1
testpath 0.3.1
Theano 1.0.1
tifffile 0.14.0
toolz 0.9.0
tornado 4.5.3
tox 2.9.1
traitlets 4.3.2
traits 4.6.0
traitsui 5.1.0
ubuntu-drivers-common 0.0.0
ufw 0.35
unattended-upgrades 0.1
unity-scope-calculator 0.1
unity-scope-chromiumbookmarks 0.1
unity-scope-colourlovers 0.1
unity-scope-devhelp 0.1
unity-scope-firefoxbookmarks 0.1
unity-scope-gdrive 0.7
unity-scope-manpages 0.1
unity-scope-openclipart 0.1
unity-scope-texdoc 0.1
unity-scope-tomboy 0.1
unity-scope-virtualbox 0.1
unity-scope-yelp 0.1
unity-scope-zotero 0.1
unity-tweak-tool 0.0.7
unwrap 0.1.1
urllib3 1.22
usb-creator 0.3.0
virtualenv 15.1.0
wcwidth 0.1.7
webencodings 0.5.1
Werkzeug 0.14.1
wheel 0.30.0
wrapt 1.10.11
xdiagnose 3.8.4.1
xkit 0.0.0
XlsxWriter 1.0.2 `

jcesardasilva commented 6 years ago

I have the same problem if I use virtualenv in RNICE, but this time it happens with python2 (Python 2.7.14) and not python3, but more verbose:

/mntdirect/_data_id16a_inhouse1/sware/pyvenvid16a/pyid16a/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
*** Error in `/mntdirect/_data_id16a_inhouse1/sware/pyvenvid16a/pyid16a/bin/python': double free or corruption (out): 0x00007f98001cc030 ***
Aborted

Could be the use of the bad PyQt library? This dependence on PyQt is really annoying when we don't have credentials to upgrade it.

vallsv commented 6 years ago

Could you try the last PyQt5? 5.10? We had a lot of segfault problems recently with PyQt5. Be careful that with Python2 and Python3 you usually don't use the same Qt version or binding, which easily can explain the difference.

t20100 commented 6 years ago

Hi,

I made a fresh virtualenv on rnice with python 2 and I could not reproduce your issue (tested with both pyqt4 and pyqt5 from the system).

Could you try to run this simple code to check if the problem comes from Qt?

from silx.gui import qt
print(qt.BINDING)
app = qt.QApplication([])
jcesardasilva commented 6 years ago

Hi Valentin, I have two independent virtualenvs, one for Python2 and another for Python3. So, no mixing in principle.

Typing what you say in python3 on Ubuntu 16, I get SegFault in the imports line:

jdasilva@gabor:~$ ipython3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from silx.gui import qt
Segmentation fault (core dumped)

In the virtualenv in RNICE, using python2, I get the following:

Python 2.7.14 (default, Dec 14 2017, 22:24:44) 
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from silx.gui import qt
   ...: print(qt.BINDING)
   ...: app = qt.QApplication([])
   ...: 
PySide

And without virtualenv I get:

Python 2.7.9 (default, Jun 29 2016, 13:08:31) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from silx.gui import qt
   ...: print(qt.BINDING)
   ...: app = qt.QApplication([])
   ...: 
PyQt4
t20100 commented 6 years ago

So for your python3 environment it cannot import PyQt... I see two options:

  1. there is a problem with PyQt installation: does from PyQt5 import Qt work?
  2. If you have multiple Qt bindings installed (but it does not look to be the case from your list of packages), we might have a flow in the way we probe which Qt binding to use and load 2 different ones....

On rnice, I also tested with PySide of the system (with a symlink in my virtualenv) and I don't have a seg fault. I am currently trying it with PySide installed from source. How did you installed it?

jcesardasilva commented 6 years ago

I've just checked with Armando and the problem was that my machine had PyQt4 installed by the system by default and I installed PyQt5. So, when using PyQt5, there is not problem, but it seems Silx was trying to import PyQt4 first. So, we deleted the python-pyqt4 and now it works. Additionally, importing PyQt4 was still ok, the problem was really that in silx/qui/qt/_qt.py there is the following: from PyQt4.QtCore import * and this was causing the SegFault. This line is still there, but since I don't have PyQt4 installed anymore, there is no problem.

vasole commented 6 years ago

@t20100

I do not know the implications of trying PyQt5 first instead of trying PyQt4 first. I would suggest to try PyQt5 first at the very least when using Python3.

A safer option for the time being would be to allow to pass a --qt-binding option to silx view so that the user can force the binding.

t20100 commented 6 years ago

silx tries to import PyQt4 first to be consistent with IPython on debian8... I would prefer to load PyQt5 first all the time, but then %pylab qt would break on debian8...

Yet in silx view it would be better to force PyQt5 if it is present (I opened #1674 for that).

t20100 commented 6 years ago

BTW importing PyQt4 does not load Qt libraries, just a pure Python module (you can import PyQt4, PyQt5 and PySide all together), problems starts with PyQtX.QtCore which really loads Qt.

vallsv commented 6 years ago

It looks like this problem is solve now? Since we close all the windows before the end of the application.

t20100 commented 6 years ago

It should be solved, please reopen if not.