I am capturing an XML dataset over http, parsing the XML and returning a value. I am doing it in an infinite loop so as to control a relay. fp = urllib2.urlopen(URL1, timeout = 60 ) doc = etree.parse(fp) fp.close() After some time of working properly, it crashes, possibly due to an internet outage. ...