Hope this is quite a simple question, but it\'s driving me crazy. I\'m using Python 2.7.3 on an out of the box installation of ubuntu 12.10 server. I kept zooming on the problem
Can try using socket.setdefaulttimeout(5) as alecxe suggested.
More details in urllib2 doc
The Python support for fetching resources from the web is layered. urllib2 uses the httplib library, which in turn uses the socket library.
As of Python 2.3 you can specify how long a socket should wait for a response before timing out. This can be useful in applications which have to fetch web pages. By default the socket module has no timeout and can hang. Currently, the socket timeout is not exposed at the httplib or urllib2 levels. However, you can set the default timeout globally for all sockets using
import socket
import urllib2
# timeout in seconds
timeout = 10
socket.setdefaulttimeout(timeout)