Skip to content

Commit 37ba3c6

Browse files
Merge pull request #40 from ISISComputingGroup/time_out_for_url_get
Time out on URL get
2 parents cc3fe96 + d514496 commit 37ba3c6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

external_webpage/data_source_reader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
# Port for configuration
3232
PORT_CONFIG = 8008
3333

34+
# Timeout for url get
35+
URL_GET_TIMEOUT = 60
36+
3437

3538
class DataSourceReader(object):
3639
"""
@@ -86,7 +89,7 @@ def _get_json_from_info_page(self, port, group_name):
8689
url = 'http://{host}:{port}/group?name={group_name}&format=json'.format(
8790
host=self._host, port=port, group_name=group_name)
8891
try:
89-
page = requests.get(url)
92+
page = requests.get(url, timeout=URL_GET_TIMEOUT)
9093
return page.json()
9194
except Exception as e:
9295
logger.error("URL not found or json not understood: " + str(url))
@@ -101,7 +104,7 @@ def read_config(self):
101104
"""
102105

103106
# read config
104-
page = requests.get('http://{}:{}/'.format(self._host, PORT_CONFIG))
107+
page = requests.get('http://{}:{}/'.format(self._host, PORT_CONFIG), timeout=URL_GET_TIMEOUT)
105108
content = page.content.decode("utf-8")
106109
corrected_page = content.replace("'", '"')\
107110
.replace("None", "null")\

webserver.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ def do_GET(self):
3434
This is called by BaseHTTPRequestHandler every time a client does a GET.
3535
The response is written to self.wfile
3636
"""
37+
instrument = "Not set"
3738
try:
3839
instrument, callback = get_instrument_and_callback(self.path)
3940

40-
# Warn level so as to avoid many log messages that come from other modules
41-
logger.warning("Connected to from " + str(self.client_address) + " looking at " + str(instrument))
41+
# Debug is only needed when debugging
42+
logger.debug("Connection from " + str(self.client_address) + " looking at " + str(instrument))
4243

4344
with scraped_data_lock:
4445
if instrument == "ALL":
@@ -61,11 +62,13 @@ def do_GET(self):
6162
self.end_headers()
6263
self.wfile.write(response.encode("utf-8"))
6364
except ValueError as e:
64-
logger.error(e)
65+
logger.exception("Value Error when getting data from {} for {}: {}".format(
66+
self.client_address, instrument, e))
6567
self.send_response(400)
6668
except Exception as e:
69+
logger.exception("Exception when getting data from {} for {}: {}".format(
70+
self.client_address, instrument, e))
6771
self.send_response(404)
68-
logger.error(e)
6972

7073
def log_message(self, format, *args):
7174
""" By overriding this method and doing nothing we disable writing to console

0 commit comments

Comments
 (0)