changeset 46:aca02ce71274

myrss_app.py: add urlopen timeout, and render time
author paulo
date Tue, 12 Feb 2013 00:43:11 -0700
parents 1d492a6d4237
children 315afeb47e52
files myrss/myrss_app.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/myrss/myrss_app.py	Tue Feb 05 02:28:40 2013 -0700
     1.2 +++ b/myrss/myrss_app.py	Tue Feb 12 00:43:11 2013 -0700
     1.3 @@ -20,6 +20,7 @@
     1.4  MAX_ITEMS = 30
     1.5  MAX_LINK_Z = 4
     1.6  MAX_THREADS = 20
     1.7 +URLOPEN_TIMEOUT = 60 # [seconds]
     1.8  
     1.9  
    1.10  _PARSE_ROOT_TAG_RE = re.compile(r"(\{(.+)\})?(.+)")
    1.11 @@ -107,6 +108,9 @@
    1.12  			p.a(it_title, href=it_link, klass="z%d" % (link_z % MAX_LINK_Z))
    1.13  			link_z += 1
    1.14  
    1.15 +	dtdelta = datetime.datetime.now() - dtnow
    1.16 +	root.div("%.3f" % (dtdelta.days*86400 + dtdelta.seconds + dtdelta.microseconds/1e6), klass="debug")
    1.17 +
    1.18  	return unicode(root).encode("utf-8")
    1.19  
    1.20  
    1.21 @@ -115,7 +119,7 @@
    1.22  
    1.23  	try:
    1.24  		logging.info("processing %s" % url)
    1.25 -		feed = urllib2.urlopen(urllib2.Request(url, headers={"User-Agent": ''}))
    1.26 +		feed = urllib2.urlopen(urllib2.Request(url, headers={"User-Agent": ''}), timeout=URLOPEN_TIMEOUT)
    1.27  	except urllib2.HTTPError as e:
    1.28  		logging.info("(%s) %s" % (url, e))
    1.29  		return ret