Re: Gtk, Python, and Threading.



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'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.
>


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