I want my program to try to open the page and get the data in time interval [0,t], if that time expires connection should be close.
I'm using urllib2 to try to accomplish the task.
t=1
url="http://example.com"
response=urllib2.urlopen(url,timeout=t)
html=response.read()
This seems to work if url exists. However, if you put some nonexistent url it takes too long for error to stop the program. And if I put this program to be used by some web site the user would need to wait for error message for too long.
Is there a way to stop execution of urlopen command if it takes longer than set time?