[pygtk] PyGTK and urllib

James Henstridge james@daa.com.au
Tue, 18 Jul 2000 09:45:48 +0800 (WST)


On Mon, 17 Jul 2000, Martijn Faassen wrote:

> Hi there,
> 
> I've run into an odd problem with urllib.urlopen() apparently taking a *lot*
> more time when used through PyGTK (using LibGlade and Gnome) than when
> I call the same routine through python only. In fact, if I call 
> urlopen() through the Gnome interface, *everything* in X seems to become
> unresponsive; the only thing I can move around is the mouse cursor, but
> since I can't click anything, it's not very useful.
> 
> Oddly enough in the same app I call urlopen() somewhere else that doesn't
> cause this kind of blocking. But I did whittle down my code and it *does*
> seem to be urlopen() in the second case.
> 
> Anyone have any suggestions?

Unless I am mistaken, urllib is a syncronous interface, so it will not
return until it has completed the transfer.  This means your application
will not process any events (mouse clicks, expose events, etc) until the
transfer completes, which is what is causing your problems.

You should either use an asyncronous transfer (using the
input_add() function to set up a handler for when information comes in on
the socket), or look at using threads.

> 
> Regards,
> 
> Martijn
> 

James.

-- 
Email: james@daa.com.au
WWW:   http://www.daa.com.au/~james/