Single write function

main
Bob Mottram 2020-09-02 17:32:50 +01:00
parent bd0783a8d5
commit 7cfa74df06
1 changed files with 5 additions and 6 deletions

View File

@ -624,9 +624,7 @@ class PubServer(BaseHTTPRequestHandler):
self.send_header('Content-Length', str(len(msg))) self.send_header('Content-Length', str(len(msg)))
self.send_header('X-Robots-Tag', 'noindex') self.send_header('X-Robots-Tag', 'noindex')
self.end_headers() self.end_headers()
try: if not self._write(msg):
self.wfile.write(msg)
except Exception as e:
print('Error when showing ' + str(httpCode)) print('Error when showing ' + str(httpCode))
print(e) print(e)
@ -685,16 +683,17 @@ class PubServer(BaseHTTPRequestHandler):
'The server is busy. Please try again ' + 'The server is busy. Please try again ' +
'later') 'later')
def _write(self, msg) -> None: def _write(self, msg) -> bool:
tries = 0 tries = 0
while tries < 5: while tries < 5:
try: try:
self.wfile.write(msg) self.wfile.write(msg)
break return True
except Exception as e: except Exception as e:
print(e) print(e)
time.sleep(1) time.sleep(0.5)
tries += 1 tries += 1
return False
def _robotsTxt(self) -> bool: def _robotsTxt(self) -> bool:
if not self.path.lower().startswith('/robot'): if not self.path.lower().startswith('/robot'):