Yes, I can confirm that adding processEvents in places to facilitate
redraws is a good way to lead to segfaults. I have seen this in many
places other than matplotlib. The reason Tk does not have this problem is
that it deals with event loops in a fundementally different way that Wx
or Qt. I am not sure what the difference is exactly, but I seem to
remember that the Tk event loop is more or less hard-wired in Python, and
(maybe ?) lives in a different C-level thread.
The problem with animations in the example linked by Pierre is that there
is no redraw triggered, because the redraw needs to be done in the event
loop. The question that needs to be answered to make it easier for people
doing animations outside of the mainloop is rather: is there a way to
force a redraw without returning in the mainloop. Chances are that there
isn't, because the toolkit (Qt) is not thread safe.
But the problem really boils down to the fact that the example is not the
right way to write animations in GUI programming. However people do not
want to learn event loop programming (I can understand them) and want to
write for loops. In Mayavi, we provide a helper function that enables to
put such a for loop in a generator and pass the generator to the event
loop framework without having to worry about timer:
While this function should work out of the box in Spyder, if the
ETS_TOOLKIT variable is well set for Mayavi/Traits to use the Qt backend,
it would also be fairly easy to port the main idea out of Mayavi and
Traits, in matplotlib or spyder:
My 2 cents,
On Sun, Nov 21, 2010 at 11:58:42AM -0500, Darren Dale wrote:
> Apparently, to make it work with the Qt4 backend, one simply has to add:
> to the method 'FigureCanvasQt.draw_idle' (matplotlib/backends/backend_qt4.py).
, discussion of why processEvents was originally removed from draw():
"that line can not be added back in. When that line
is in place, the backend attempts to process queued events before it
is finished processing the current event. It was leading to segfaults
in some cases. processEvents should not be called in the middle of
processing an event."