From d3e4616b6572b8918f62a8b65c9f4f08d7de2735 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Wed, 25 May 2016 16:19:36 +0200 Subject: [PATCH] First attempt to handle the nasty socket timeout Retry once if a http get fails --- scripts/python/terrasync.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/python/terrasync.py b/scripts/python/terrasync.py index aeb195665..6798a1edc 100755 --- a/scripts/python/terrasync.py +++ b/scripts/python/terrasync.py @@ -43,24 +43,24 @@ class HTTPGetter: self.httpConnection = HTTPConnection(self.parsedBaseUrl.netloc,80, True) self.httpRequestHeaders = headers = {'Host':self.parsedBaseUrl.netloc,'Content-Length':0,'Connection':'Keep-Alive','User-Agent':'FlightGear terrasync.py'} - def get(self, httpGetCallback): - - #self.requests.append(httpGetCallback) + def doGet(self, httpGetCallback): conn = self.httpConnection request = httpGetCallback - conn.request("GET", self.parsedBaseUrl.path + request.src, None, self.httpRequestHeaders) + self.httpConnection.request("GET", self.parsedBaseUrl.path + request.src, None, self.httpRequestHeaders) + httpGetCallback.result = self.httpConnection.getresponse() + httpGetCallback.callback() + + def get(self, httpGetCallback): + try: - httpGetCallback.result = conn.getresponse() + self.doGet(httpGetCallback) except: # try to reconnect once #print("reconnect") - conn.close() - conn.connect() - conn.request("GET", self.parsedBaseUrl.path + request.src, None, self.httpRequestHeaders) - httpGetCallback.result = conn.getresponse() + self.httpConnection.close() + self.httpConnection.connect() + self.doGet(httpGetCallback) - httpGetCallback.callback() - #self.requests.remove(httpGetCallback) ################################################################################################################################# class DirIndex: -- 2.39.5