casync: reuse requests session in RemoteChunkReader (#25045)

pull/25046/head
Willem Melching 3 years ago committed by GitHub
parent 59c28611a4
commit 50434d612e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      system/hardware/tici/casync.py

@ -55,6 +55,7 @@ class RemoteChunkReader(ChunkReader):
def __init__(self, url: str) -> None: def __init__(self, url: str) -> None:
super().__init__() super().__init__()
self.url = url self.url = url
self.session = requests.Session()
def read(self, chunk: Chunk) -> bytes: def read(self, chunk: Chunk) -> bytes:
sha_hex = chunk.sha.hex() sha_hex = chunk.sha.hex()
@ -62,7 +63,7 @@ class RemoteChunkReader(ChunkReader):
for i in range(CHUNK_DOWNLOAD_RETRIES): for i in range(CHUNK_DOWNLOAD_RETRIES):
try: try:
resp = requests.get(url, timeout=CHUNK_DOWNLOAD_TIMEOUT) resp = self.session.get(url, timeout=CHUNK_DOWNLOAD_TIMEOUT)
break break
except Exception: except Exception:
if i == CHUNK_DOWNLOAD_RETRIES - 1: if i == CHUNK_DOWNLOAD_RETRIES - 1:

Loading…
Cancel
Save