[gimp-web/wip/Jehan/fix-ci] tools: test timing out?
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-web/wip/Jehan/fix-ci] tools: test timing out?
- Date: Mon, 2 May 2022 15:37:31 +0000 (UTC)
commit 3c6e9007a5393214905c7766d4ac18cb473c8d57
Author: Jehan <jehan girinstud io>
Date: Mon May 2 17:37:11 2022 +0200
tools: test timing out?
tools/downloads/gimp-check-mirrors.py | 76 ++++++++++++++++++++---------------
1 file changed, 44 insertions(+), 32 deletions(-)
---
diff --git a/tools/downloads/gimp-check-mirrors.py b/tools/downloads/gimp-check-mirrors.py
index 8c3766a2..95654930 100755
--- a/tools/downloads/gimp-check-mirrors.py
+++ b/tools/downloads/gimp-check-mirrors.py
@@ -98,39 +98,51 @@ def verify_remote(uri, future):
success = False
status = None
checksum_ok = None
- try:
- if future is not None:
- headers = {'user-agent': 'Mozilla/5.0'}
- with requests.get(uri, headers=headers, stream=True) as response:
- m = hashlib.sha256()
- # I don't think the chunk_size is useful, since docs
- # says that "stream=True will read data as it arrives
- # in whatever size the chunks are received" which is
- # the ideal way. But if it doesn't, let's use 2**16 as
- # a reasonable chunk size to process.
- for line in response.iter_content(chunk_size=65536, decode_unicode=False):
- m.update(line)
- if m.digest() == future.result():
- checksum_ok = True
- success = True
- else:
- checksum_ok = False
+ tries = 3
+ while tries > 0:
+ tries -= 1
+ try:
+ if future is not None:
+ headers = {'user-agent': 'Mozilla/5.0'}
+ with requests.get(uri, headers=headers, stream=True, timeout=10) as response:
+ m = hashlib.sha256()
+ # I don't think the chunk_size is useful, since docs
+ # says that "stream=True will read data as it arrives
+ # in whatever size the chunks are received" which is
+ # the ideal way. But if it doesn't, let's use 2**16 as
+ # a reasonable chunk size to process.
+ for line in response.iter_content(chunk_size=65536, decode_unicode=False):
+ m.update(line)
+ if m.digest() == future.result():
+ checksum_ok = True
+ success = True
+ else:
+ checksum_ok = False
+ status = str(response.status_code)
+ else:
+ response = requests.head(url=uri, timeout=20, allow_redirects=True)
status = str(response.status_code)
- else:
- response = requests.head(url=uri, timeout=20, allow_redirects=True)
- status = str(response.status_code)
- if response.status_code == 200:
- success = True
- except requests.exceptions.ConnectionError as error:
- status = 'Connection error'
- except requests.exceptions.ConnectTimeout as error:
- status = 'Connection timed out'
- except requests.exceptions.ReadTimeout as error:
- status = 'Read timed out'
- except requests.exceptions.TooManyRedirects as error:
- status = 'Too many redirects'
- except OSError as error:
- status = str(error.strerror)
+ if response.status_code == 200:
+ success = True
+ # Exit the loop.
+ break
+ # This API apparently doesn't like interruption of network and ends
+ # up waiting forever in some cases. Let's retry in such case.
+ except requests.exceptions.ConnectTimeout as error:
+ status = 'Connection timed out'
+ print("{}: RETRYING {}".format(status, uri)
+ except requests.exceptions.ReadTimeout as error:
+ status = 'Read timed out'
+ print("{}: RETRYING {}".format(status, uri)
+ except requests.exceptions.ConnectionError as error:
+ status = 'Connection error'
+ break
+ except requests.exceptions.TooManyRedirects as error:
+ status = 'Too many redirects'
+ break
+ except OSError as error:
+ status = str(error.strerror)
+ break
return uri, success, status, checksum_ok
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]