Merge branch '2.5.x' into 2.5.x-saas

Conflicts:
	python_apps/pypo/listenerstat.py
This commit is contained in:
Albert Santoni 2014-02-05 17:35:59 -05:00
commit 02a96646e1
27 changed files with 15828 additions and 73 deletions

View file

@ -10,6 +10,7 @@ import sys
import time
import urllib
import urllib2
import socket
import logging
import json
import base64
@ -121,6 +122,9 @@ class ApcUrl(object):
else: return self.base_url
class ApiRequest(object):
API_HTTP_REQUEST_TIMEOUT = 30 # 30 second HTTP request timeout
def __init__(self, name, url, logger=None):
self.name = name
self.url = url
@ -134,9 +138,15 @@ class ApiRequest(object):
self.logger.debug(final_url)
try:
req = urllib2.Request(final_url, _post_data)
f = urllib2.urlopen(req)
f = urllib2.urlopen(req, timeout=ApiRequest.API_HTTP_REQUEST_TIMEOUT)
content_type = f.info().getheader('Content-Type')
response = f.read()
#Everything that calls an ApiRequest should be catching URLError explicitly
#(according to the other comments in this file and a cursory grep through the code)
#Note that URLError can occur for timeouts as well as socket.timeout
except socket.timeout:
self.logger.error('HTTP request to %s timed out', final_url)
raise
except Exception, e:
#self.logger.error('Exception: %s', e)
#self.logger.error("traceback: %s", traceback.format_exc())
@ -277,7 +287,7 @@ class AirtimeApiClient(object):
try:
request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request).read().strip()
response = urllib2.urlopen(request, timeout=ApiClient.API_HTTP_REQUEST_TIMEOUT).read().strip()
logger.info("uploaded show result %s", response)
break

View file

@ -11,4 +11,4 @@ SCRIPT=`readlink -f $0`
SCRIPTPATH=`dirname $SCRIPT`
cd ${SCRIPTPATH}/../
timeout 45 python pyponotify.py "$@"
timeout --signal=KILL 45 python pyponotify.py "$@"

View file

@ -10,6 +10,9 @@ import time
from api_clients import api_client
class ListenerStat(Thread):
HTTP_REQUEST_TIMEOUT = 30 # 30 second HTTP request timeout
def __init__(self, config, logger=None):
Thread.__init__(self)
self.config = config
@ -47,7 +50,7 @@ class ListenerStat(Thread):
url=url,
headers=header)
f = urllib2.urlopen(req)
f = urllib2.urlopen(req, timeout=ListenerStat.HTTP_REQUEST_TIMEOUT)
document = f.read()
return document