[pygtk] urllib2 use within an idle_add generator

Jamie Norrish Jamie.Norrish at vuw.ac.nz
Wed Jul 22 07:28:19 WST 2009


Within my application, one piece of functionality is to loop over a
number of items, fetch a URL resource for each, and update items in a
TreeView based on the contents of the returned resource. Since I have
something similar, that doesn't involve the URL fetching, I wanted to
implement it in the same way, namely using a generator function
referenced via idle_add, with each iteration of the loop yielding.

However, as per FAQ 20.9, the new code hangs on urllib2.urlopen(url). I
have tried using gobject.io_add_watch (as per FAQ 20.16) within the
generator, just to see whether I could get something happening, but it
still hangs. Interrupting the program shows that it is hanging in
readline in socket.py, reading from the opened URL resource.

Is there any way of using the generator approach with each pass calling
urllib2, or do I need to reimplement this piece of functionality with
threads?

Jamie



More information about the pygtk mailing list