Re: Gtk, Python, and Threading.



On Tue, 2010-12-14 at 09:28 +0100, Tomeu Vizoso wrote:
> On Mon, Dec 13, 2010 at 19:56, Robert Park <rbpark exolucere ca> wrote:
> > Alright, so threading is an absolute nightmare and I've tried every
> > different example I could find in every different way I could think
> > of. I peppered thread_enter/thread_leave everywhere I could possibly
> > imagine, and the thread just plain blocks. Even if the entirety of the
> > thread code is just a single print statement, it blocks until the
> > interface gets clicked.
> >
> > I. Give. Up.
> 
> I try to avoid threads at all in my python programs.

I never have any trouble on Linux when mixing threading and pygtk. Are
you seeing these problems using pygtk or PyGObject+introspection?

John

[1] I typically use the gobject.idle_add(gobject.emit, "foo", bar, baz)
idiom to communicate from threading.Thread derived objects back to the
UI. On windows things also work well providing one enters/leaves before
running the main loop.

I don't bother with the threads_enter and threads_leave approach.

> 
> > I'm looking at using Gio.File().read_async() instead, but thankfully
> > there's not a lick of documentation that makes any sense whatsoever.
> >
> > class GeoNamesDownloader(object):
> >    def get(self, data, url):
> >        self.stream = Gio.File(url)
> >        self.stream.read_async(self.read)
> >
> >    def read(self, gdaemonfile, result):
> >        print self.stream.read_finish(result).read()[:100]
> >
> > GeoNamesDownloader().get(None, 'http://www.google.ca')
> >
> > This is almost word for word from the pygobject documentation, and
> > this is the result:
> >
> > Traceback (most recent call last):
> >  File "./gottengeography.py", line 1306, in <module>
> >    GeoNamesDownloader().get(None, 'http://www.google.ca')
> >  File "./gottengeography.py", line 1300, in get
> >    self.stream = Gio.File(url)
> > TypeError: GInterface.__init__() takes exactly 0 arguments (1 given)
> 
> Interfaces cannot be instantiated, use something like instead:
> 
> http://library.gnome.org/devel/gio/2.25/GFile.html#g-file-new-for-path
> 
> Regards,
> 
> Tomeu
> 
> > RAAAAAAAAAAAAAAAAAAAAAAAAAAGE!!!!!!!!!!
> >
> > (and if I take out the argument, I get this)
> >
> > Traceback (most recent call last):
> >  File "./gottengeography.py", line 1306, in <module>
> >    GeoNamesDownloader().get(None, 'http://www.google.ca')
> >  File "./gottengeography.py", line 1300, in get
> >    self.stream = Gio.File()
> > NotImplementedError: File can not be constructed
> >
> > Fun.
> >
> _______________________________________________
> python-hackers-list mailing list
> python-hackers-list gnome org
> http://mail.gnome.org/mailman/listinfo/python-hackers-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]