def read(url):
    stream = urllib.request.urlopen(url)
return stream.read()

def handler(signum, frame):
    raise IOError('The page is taking too long to read')
signal.signal(signal.SIGALRM, handler)
signal.alarm(5)
try:
    output = read('http://www.google.de/images/nav_logo4.png')
except IOError:
    pass
reading a stream made by urllib2 never recovers when connection got interrupted