urllib2.urlopen timeout

Zdenek Maxa zdenekmaxa at yahoo.co.uk
Mon Aug 3 05:19:11 EDT 2009


Hi,

I would like to ask how I should set timeout for a call:

f = urllib2.urlopen(url)

I am using Python 2.5. I have already tried
socket.setdefaulttimeout(3). However, this adversely affects other
connections the application makes, since it seems to affect all socket
connections.

I know that Python 2.6 offers
urllib2.urlopen(url[, data][, timeout])
which would elegantly solved my problem, but I have to stick to Python 2.5.

I am doing urlopen in a thread so I want to avoid really long hanging on
this call, which happens at times, until some default timeout ticks out.

All hints appreciated.

Thanks,
Zdenek



More information about the Python-list mailing list