JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
476 stars 87 forks source link

Segfault in figure() when package Gtk imported #199

Open rdeits opened 8 years ago

rdeits commented 8 years ago

When running the following code, I get a segfault:

using PyPlot
import Gtk
figure()

I'm on Ubuntu 14.04, with libgtk-3-dev (3.10.8-0ubuntu1.6) installed. I've reproduced the segfault with both the most recent tagged versions of Gtk.jl, PyCall.jl, and PyPlot.jl as well as the master branches of all of those packages.

The error message I get is:

julia:11038): GLib-GObject-WARNING **: cannot register existing type 'GdkDisplayManager'

(julia:11038): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

(julia:11038): GLib-GObject-CRITICAL **: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

(julia:11038): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(julia:11038): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(julia:11038): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(julia:11038): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(julia:11038): GLib-GObject-WARNING **: cannot register existing type 'GdkDisplay'

(julia:11038): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

(julia:11038): GLib-GObject-CRITICAL **: g_type_register_static: assertion 'parent_type > 0' failed

(julia:11038): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed

(julia:11038): GLib-GObject-CRITICAL **: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

signal (11): Segmentation fault
gdk_display_open at /usr/bin/../lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (unknown line)
gdk_display_open_default_libgtk_only at /usr/bin/../lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (unknown line)
gtk_init_check at /usr/bin/../lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (unknown line)
gtk_init at /usr/bin/../lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (unknown line)
unknown function (ip: 0x7f0a838b9b37)
_ZN18QGuiPlatformPlugin19systemIconThemeNameEv at /usr/bin/../lib/x86_64-linux-gnu/libQtGui.so.4 (unknown line)
unknown function (ip: 0x7f0a835e1f24)
unknown function (ip: 0x7f0a835a703e)
unknown function (ip: 0x7f0a835ab2b1)
_ZN19QApplicationPrivate9constructEP9_XDisplaymm at /usr/bin/../lib/x86_64-linux-gnu/libQtGui.so.4 (unknown line)
_ZN12QApplicationC2ERiPPci at /usr/bin/../lib/x86_64-linux-gnu/libQtGui.so.4 (unknown line)
unknown function (ip: 0x7f0a84546f3e)
unknown function (ip: 0x7f0a84547131)
unknown function (ip: 0x7f0aa4aa3b4c)
unknown function (ip: 0x7f0a88a0868f)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalFrameEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalCodeEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalFrameEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalCodeEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
unknown function (ip: 0x7f0a88a996d0)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
unknown function (ip: 0x7f0a889917bd)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalFrameEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalCodeEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
unknown function (ip: 0x7f0a88a996d0)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
unknown function (ip: 0x7f0a889917bd)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
unknown function (ip: 0x7f0a88a0a67f)
unknown function (ip: 0x7f0a88a0868f)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalFrameEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalCodeEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalFrameEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalCodeEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
unknown function (ip: 0x7f0a88a997a5)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalFrameEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
PyEval_EvalCodeEx at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
unknown function (ip: 0x7f0a88a996d0)
PyObject_Call at /usr/bin/../lib/x86_64-linux-gnu/libpython2.7.so (unknown line)
pycall at /home/rdeits/.julia/v0.4/PyCall/src/exception.jl:78
figure at /home/rdeits/.julia/v0.4/PyPlot/src/PyPlot.jl:442
julia_figure_21540 at  (unknown line)
jl_apply_generic at /usr/bin/../lib/x86_64-linux-gnu/julia/libjulia.so (unknown line)
unknown function (ip: 0x7f0cadd8d683)
unknown function (ip: 0x7f0cadd8cac1)
unknown function (ip: 0x7f0cadda1ca8)
unknown function (ip: 0x7f0cadda2999)
jl_load at /usr/bin/../lib/x86_64-linux-gnu/julia/libjulia.so (unknown line)
include at ./boot.jl:261
jl_apply_generic at /usr/bin/../lib/x86_64-linux-gnu/julia/libjulia.so (unknown line)
include_from_node1 at ./loading.jl:304
jl_apply_generic at /usr/bin/../lib/x86_64-linux-gnu/julia/libjulia.so (unknown line)
process_options at ./client.jl:284
_start at ./client.jl:378
unknown function (ip: 0x7f0caa977f49)
jl_apply_generic at /usr/bin/../lib/x86_64-linux-gnu/julia/libjulia.so (unknown line)
unknown function (ip: 0x401b09)
unknown function (ip: 0x4016df)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x401725)
unknown function (ip: (nil))
[1]    11038 segmentation fault (core dumped)  julia test_segfault.jl

I came across this segfault while trying to use https://github.com/timholy/ProfileView.jl (which indirectly imports Gtk.jl) on a module that also used PyPlot.

Has anyone encountered this before?

stevengj commented 8 years ago

On Ubuntu, I think PyPlot defaults to the Gtk backend. However, by also loading the Julia Gtk package, you are trying to process the Gtk event loop twice (once in the Julia Gtk package and once in Python), and it's not surprising that it fails.

One option would be to load PyPlot using a different, not-Gtk, backend. e.g. TkAgg. You can change the default backend in a variety of ways, e.g. in your .matplotlibrc file , via the MPLBACKEND environment variable, or by using PyCall; PyDict(matplotlib["rcParams"])["backend"] = "tkagg"

rdeits commented 8 years ago

Ah, that makes sense, thanks!

I've actually tried loading PyPlot with different backends, but so far haven't been able to prevent the segfault. For example, I can do the following:

using PyCall
@pyimport matplotlib
PyDict(matplotlib.rcParams)["backend"] = "tkagg"
import PyPlot
import Gtk

PyPlot.figure()

and I still get the segfault. Substituting "qt" for "tkagg" also segfaults. Likewise, I tried following the instructions from the Readme to set the backend:

using PyCall
pygui(:qt)
import PyPlot
import Gtk

PyPlot.figure()

but that also segfaults with the same stack trace.

nzqo commented 6 years ago

I'm having the same problem, did someone find a fix for this yet?

cmey commented 6 years ago

+1 here's the complete log on Travis