[pygtk] Refreshing a Tree Store/Tree View within a thread crashes randomly

Lionel Dricot zeploum at gmail.com
Sun Jan 25 20:29:19 WST 2009


John,

Thank you !

Your answer is short, complete, precise and solved my problem in 3 minutes
(just replacing my Thread() line by an idle_add)

You saved my day :-)

Lionel

On Sun, Jan 25, 2009 at 6:10 AM, John Stowers
<john.stowers.lists at gmail.com>wrote:

> On Sun, 2009-01-25 at 02:57 +0100, Lionel Dricot wrote:
> > Hello,
> >
> > I'm displaying a TreeStore in a TreeView and I want to refresh them
> > when I receive the gobject signal "refresh".
> >
> > Because my refresh can be heavy and I don't want to refresh 10 times
> > when not needed, the refresh is handled in a thread. The principle is
> > the following :
>
> Simple, Gtk is not threadsafe!
>
> Do not touch the GUI from the non main thread (unless you acquire the
> gtk lock)
>
> Advice on handling Threads with (py)Gtk can be found
>
> http://faq.pygtk.org/index.py?req=show&file=faq20.001.htp
> http://www.johnstowers.co.nz/blog/index.php/2007/03/12/threading-and-pygtk/
> http://unpythonic.blogspot.com/2007/08/using-threads-in-pygtk.html
> http://www.oreillynet.com/onlamp/blog/2006/07/pygtk_and_threading.html
>
> John
>
> >
> > SignalEmitter.connect("refresh",self.do_refresh)
> >
> > do_refresh()
> >     thread(self.general_refresh)
> >
> > general_refresh()
> >     if self.lock.acquire(False) :
> >         refresh_treestore()
> >         self.lock.release()
> >
> > refresh_treestore() :
> > At first, I was emptying the TreeStore then added the elements but
> > I've seen somewhere on the web that it might be better to create a new
> > TreeStore then to set_model on the TreeView
> >
> >
> > Unfortunatly, it crashes randomly with the error :
> >
> > /home/ploum/code/gtg/taskbrowser/browser.py:180: GtkWarning:
> > gtk_tree_store_get_value: assertion `VALID_ITER (iter, tree_store)'
> > failed
> >   gtk.main()
> > /home/ploum/code/gtg/taskbrowser/browser.py:180: Warning:
> > g_object_set_property: assertion `G_IS_VALUE (value)' failed
> >   gtk.main()
> > /home/ploum/code/gtg/taskbrowser/browser.py:180: Warning:
> > g_value_unset: assertion `G_IS_VALUE (value)' failed
> >   gtk.main()
> >
> > The crash can happen at start, it can happen after 10 minutes, it's
> > completely random. Also, the crash always happens after the lock is
> > released.
> >
> > I've no idea why it crashes like this and any help would be greatly
> > appreciated !
> >
> >
> > If you are motivated enough to try the real code, I've put a bzr
> > branch on https://code.edge.launchpad.net/~gtg/gtg/threaded<https://code.edge.launchpad.net/%7Egtg/gtg/threaded>.
> simply
> > do :
> >
> > bzr branch lp:~gtg/gtg/threaded
> >
> > The code is in taskbrowser/browser.py  (refresh_treestore is called
> > refresh_ts).
> >
> > (and if you want to see the application in its normal shape, just do
> > bzr branch lp:gtg )
> >
> > Thanks a lot for your (future) help,
> >
> > Lionel
> > _______________________________________________
> > pygtk mailing list   pygtk at daa.com.au
> > http://www.daa.com.au/mailman/listinfo/pygtk
> > Read the PyGTK FAQ: http://faq.pygtk.org/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090125/0d7244a0/attachment.htm 


More information about the pygtk mailing list