Bug 407362 - python3 backend broke down when calling matplotlib.pyplot.plot()
Summary: python3 backend broke down when calling matplotlib.pyplot.plot()
Status: RESOLVED FIXED
Alias: None
Product: cantor
Classification: Applications
Component: python3-backend (show other bugs)
Version: 19.04
Platform: Manjaro Linux
: NOR major
Target Milestone: ---
Assignee: Nikita Sirgienko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-09 13:32 UTC by LiTuX
Modified: 2019-07-04 21:50 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 19.08
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description LiTuX 2019-05-09 13:32:59 UTC
SUMMARY
python3 backend broke down when calling matplotlib.pyplot.plot(). Cantor will always show the following message before 'restart backend':
The name org.kde.Cantor.Python3-#### was not provided by any .service files

STEPS TO REPRODUCE
1. Create a python 3 worksheet;

2. Insert the following python code:
``` python
import numpy as np
import matplotlib.pyplot as plt

foo = np.random.rand(10);
```
Shift Enter to run the entry, and everything is fine;

3. Try plot something. Insert
``` python
plt.plot(foo)
```
Then Shift-Enter.

OBSERVED RESULT
The name org.kde.Cantor.Python3-#### was not provided by any .service files

EXPECTED RESULT
A figure with a line should be plotted below the entry.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Manjaro Linux, kernel 4.19.36-1-MANJARO
(available in About System)
KDE Plasma Version: 5.15.4
KDE Frameworks Version: 5.57.0
Qt Version: 5.12.3

ADDITIONAL INFORMATION
Comment 1 Nikita Sirgienko 2019-05-09 17:27:37 UTC
Can't reproduce it on Ubuntu, so, I think, it's platform specific problem.
Is this code works in python console?
Comment 2 Nikita Sirgienko 2019-05-09 19:40:09 UTC
I hade reproduce the problem on 4.19.28-1-MANJARO -- crash inside Cantor python server with this code and no problem in python3 cli.
Comment 3 Nikita Sirgienko 2019-05-12 16:01:51 UTC
Crash trace of cantor_python3server. Actual crash happens inside PyEval_EvalCode function (trace below). In that moment argument of runPythonCommand was "plot.show(foo)".

#0  0x00007f21c370f82f in raise () from /usr/lib/libc.so.6
#1  0x00007f21c36fa672 in abort () from /usr/lib/libc.so.6
#2  0x00007f21c3c1c7fc in QMessageLogger::fatal(char const*, ...) const ()
   from /usr/lib/libQt5Core.so.5
#3  0x00007f21c4875f55 in ?? () from /usr/lib/libQt5Widgets.so.5
#4  0x00007f21b7e52e4a in ?? () from /usr/lib/python3.7/site-packages/PyQt5/QtWidgets.so
#5  0x00007f21b7e52f58 in ?? () from /usr/lib/python3.7/site-packages/PyQt5/QtWidgets.so
#6  0x00007f21bc6856cc in ?? () from /usr/lib/python3.7/site-packages/PyQt5/sip.so
#7  0x00007f21c4eb4ea5 in ?? () from /usr/lib/libpython3.7m.so.1.0
#8  0x00007f21c4f1962c in _PyObject_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#9  0x00007f21c4f5e4b1 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#10 0x00007f21c4ea5d09 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#11 0x00007f21c4eec882 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#12 0x00007f21c4f59f9c in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#13 0x00007f21c4ea5d09 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#14 0x00007f21c4ea6f8c in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#15 0x00007f21c4eb6818 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#16 0x00007f21c4f050e3 in ?? () from /usr/lib/libpython3.7m.so.1.0
#17 0x00007f21c4f1939c in _PyObject_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#18 0x00007f21c4f5e0db in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#19 0x00007f21c4eec6db in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#20 0x00007f21c4f5d6ea in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#21 0x00007f21c4ea5d09 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
--Type <RET> for more, q to quit, c to continue without paging--
#22 0x00007f21c4ea6f8c in _PyFunction_FastCallDict () from /usr/lib/libpython3.7m.so.1.0
#23 0x00007f21c4eb6818 in _PyObject_Call_Prepend () from /usr/lib/libpython3.7m.so.1.0
#24 0x00007f21c4ea749b in PyObject_Call () from /usr/lib/libpython3.7m.so.1.0
#25 0x00007f21c4f5a83e in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#26 0x00007f21c4ea5d09 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#27 0x00007f21c4eec882 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#28 0x00007f21c4f5922d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#29 0x00007f21c4eec6db in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#30 0x00007f21c4f5922d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#31 0x00007f21c4ea5d09 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#32 0x00007f21c4eec882 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#33 0x00007f21c4f5922d in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#34 0x00007f21c4ea5d09 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#35 0x00007f21c4eec882 in _PyFunction_FastCallKeywords () from /usr/lib/libpython3.7m.so.1.0
#36 0x00007f21c4f5d6ea in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.7m.so.1.0
#37 0x00007f21c4ea5d09 in _PyEval_EvalCodeWithName () from /usr/lib/libpython3.7m.so.1.0
#38 0x00007f21c4ea6c64 in PyEval_EvalCodeEx () from /usr/lib/libpython3.7m.so.1.0
#39 0x00007f21c4ea6c8c in PyEval_EvalCode () from /usr/lib/libpython3.7m.so.1.0
#40 0x00005569ab8249a1 in PythonServer::runPythonCommand (this=0x7ffe9431dcd0, command=...)
    at /home/mmmm1998/cantor/src/backends/python/pythonserver.cpp:92
...

Also, in crash moment, cantor_python3server prints "QWidget: Cannot create a QWidget without QApplication".
Needs additional research.
Comment 4 Nikita Sirgienko 2019-05-30 15:37:08 UTC
I hade created issue (https://github.com/matplotlib/matplotlib/issues/14381) about this problem in matplotlib bug tracker.

Not sure, that this is them bug, but, I think good place to start, because I can't reproduce this error outside Cantor (but backtrace means, what crash caused not by Cantor) and have no idea that cause the problem.
Comment 5 vialav 2019-06-03 09:41:48 UTC
Confirmed on my system with Cantor 19.07.70+git20190531.

Executed in Jupyter Qt Console (ouside Cantor) where was no problem with this particular example, and it has produces a plot.
Comment 6 Nikita Sirgienko 2019-07-04 20:04:25 UTC
The problem have found: it is conflict between already loaded qt libraries (often from system installation) and qt libraries loading by PyQt5, when matplotlib import PyQt5 on pythons3server. When qt version of system and pyqt5 don't match, crash have been happening.
I will fix it in a day, or two.
Comment 7 Nikita Sirgienko 2019-07-04 21:50:49 UTC
Git commit 2329f29edc8d83b4823995a184ed454b580f0809 by Nikita Sirgienko.
Committed on 04/07/2019 at 21:45.
Pushed by sirgienko into branch 'master'.

[Python] Don't use Qt in pythonserver executable for avoding problems with PyQt5
Related: bug 397264
FIXED-IN: 19.08

M  +33   -33   src/backends/python/pythonserver.cpp
M  +11   -13   src/backends/python/pythonserver.h
M  +93   -95   src/backends/python/pythonservermain.cpp
M  +14   -2    src/backends/python/pythonsession.cpp
M  +1    -1    src/backends/python2/CMakeLists.txt
M  +1    -1    src/backends/python3/CMakeLists.txt

https://commits.kde.org/cantor/2329f29edc8d83b4823995a184ed454b580f0809