python - limit urllib getcode to specific time, to avoid freeze -
i have written code, info rss feed, , it's working great. however, feed working with, seems unreliable, , down. hence have added feature check if site up, , if isn't, wait min seek again.
i noticed today, have tendency freeze up, , have restart programme create work again.
my guess is, has problems getting '200' website.
how can set 'time limit' how long should seek sitestatus, before skipping?
i utilize python 2.7
here code have:
try: urllib.urlopen(sites).getcode() == 200 # more code here except: t = findsites(sites) print 'failed connect ' + t
thanks
edit: thanks. trying code, , should work now
you utilize urllib2.urlopen, supports timeout:
urllib2.urlopen(url[, data][, timeout])
python website urllib freeze
No comments:
Post a Comment