From 0e5b9223abbf81f934a0bd810a0790f44475e290 Mon Sep 17 00:00:00 2001 From: Moutupsi Date: Mon, 17 Apr 2017 15:41:48 -0700 Subject: [PATCH] Configure a timeout on SenderBase. Helps with Issue-16 (#34) --- applicationinsights/channel/SenderBase.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/applicationinsights/channel/SenderBase.py b/applicationinsights/channel/SenderBase.py index c31116e..8b2c983 100644 --- a/applicationinsights/channel/SenderBase.py +++ b/applicationinsights/channel/SenderBase.py @@ -25,6 +25,7 @@ class SenderBase(object): self._service_endpoint_uri = service_endpoint_uri self._queue = None self._send_buffer_size = 100 + self._timeout = 10 @property def service_endpoint_uri(self): @@ -63,6 +64,21 @@ class SenderBase(object): """ return self._queue + @property + def send_timeout(self): + """Time in seconds that the sender should wait before giving up.""" + return self._timeout + + @send_timeout.setter + def send_timeout(self, seconds): + """Configures the timeout in seconds the sender waits for a response for the server. + + Args: + seconds(float). Timeout in seconds. + """ + + self._send_buffer_size = seconds + @queue.setter def queue(self, value): """The queue that this sender is draining. While :class:`SenderBase` doesn't implement any means of doing @@ -115,7 +131,7 @@ class SenderBase(object): request = HTTPClient.Request(self._service_endpoint_uri, bytearray(request_payload, 'utf-8'), { 'Accept': 'application/json', 'Content-Type' : 'application/json; charset=utf-8' }) try: - response = HTTPClient.urlopen(request) + response = HTTPClient.urlopen(request, timeout=self._timeout) status_code = response.getcode() if 200 <= status_code < 300: return