You wonder how to set a timeout on your HTTP connection?
Try like this:
import socket
import urllib2
socket.setdefaulttimeout(3) # 3 seconds
request = urllib2.Request('http://www.yourhost.com')
response = urllib2.urlopen(req)
#urllib2.urlopen will now uses the default timeout of 3 secs.