pygtk/matplotlib/threading

Hi,

I'm using matplotlib with pygtk in a threaded application. I've seen some intermittent hangs, that I think arise from a gtk.gdk.threads_enter/leave pair missing in matplotlib.

From the gtk/pygtk documentation, gtk idle functions need to be protected

by these locks, but in lib/matplotlib/backends/backend_gtk.py, there is an idle function:

  def draw_idle(self):
         def idle_draw(*args):
             self.draw()
             self._idle_draw_id = 0
             return False
         if self._idle_draw_id == 0:
             self._idle_draw_id = gobject.idle_add(idle_draw)

That I think should be:

  def draw_idle(self):
         def idle_draw(*args):
             gtk.gdk.threads_enter()
             self.draw()
             self._idle_draw_id = 0
             gtk.gdk.threads_leave()
             return False
         if self._idle_draw_id == 0:
             self._idle_draw_id = gobject.idle_add(idle_draw)

It looks like there are other idle functions added that might need to be protected (delf.idle_event) - but those are handled in backend_bases.py, and I haven't dug in enough to see how to deal with those. Perhaps one could just document that any idle functions added by the user need to be protected?

I'm using matplotlib 1.0.1 with python 2.7.2 on Gentoo linux.

Carl