Skip to content

Commit f714cf9

Browse files
Paul JenningsPaul Jennings
authored andcommitted
Randomized delay after failed connection.
1 parent f6448ab commit f714cf9

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

TStat.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import urllib
5151
import logging
5252
import random
53+
import socket
5354
import time
5455

5556
# For Python < 2.6, this json module:
@@ -141,9 +142,12 @@ def _post(self, key, value):
141142
response = None
142143
count = 0
143144
while response is None and count < 5:
144-
conn = self._getConn()
145-
conn.request("POST", location, params, headers)
146-
response = conn.getresponse()
145+
try:
146+
conn = self._getConn()
147+
conn.request("POST", location, params, headers)
148+
response = conn.getresponse()
149+
except socket.error:
150+
response = None
147151
if response is None:
148152
time.sleep(count*random.randint(0, 3))
149153
count = count + 1
@@ -211,9 +215,12 @@ def _get(self, key, raw=False):
211215
response = None
212216
count = 0
213217
while response is None and count < 5:
214-
conn = self._getConn()
215-
conn.request("GET", getter[0])
216-
response = conn.getresponse()
218+
try:
219+
conn = self._getConn()
220+
conn.request("GET", getter[0])
221+
response = conn.getresponse()
222+
except socket.error:
223+
response = None
217224
if response is None:
218225
time.sleep(count*random.randint(0, 10))
219226
count = count + 1

0 commit comments

Comments
 (0)