Skip to content

Commit b126171

Browse files
committed
WIP
1 parent 496bed0 commit b126171

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/parallel_http_client/_client.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,21 @@ async def _fetch_range(
585585
hdr = {"Range": r_text}
586586
event = f"GET {url!s} range {r_text} to {part_file!s}"
587587
self._start_stamp(event)
588-
async with httpx.AsyncClient(http2=True, follow_redirects=True) as c:
589-
async with c.stream("GET", url, headers=hdr) as r:
590-
await self._write_file(part_file, r)
588+
timeout = httpx.Timeout(5.0, connect=10.0)
589+
try:
590+
async with httpx.AsyncClient(
591+
http2=True, follow_redirects=True, timeout=timeout
592+
) as c:
593+
async with c.stream("GET", url, headers=hdr) as r:
594+
await self._write_file(part_file, r)
595+
except Exception:
596+
self._logger.warning(
597+
f"HTTP GET {url} range {byte_range!s} failed; returning"
598+
" chunk to queue"
599+
)
600+
self._lock.acquire()
601+
self._chunks.append(byte_range)
602+
self._lock.release()
591603
self._end_stamp(event)
592604

593605
async def _reassemble_file_parts(

tests/client_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ def test_multithreaded(range_server: None, fake_fs: FakeFilesystem) -> None:
4444
assert reference.read_text() == output.read_text()
4545

4646

47-
# The multiprocess stuff doesn't work well with fake_fs.
48-
# Seems to be fine in the field.
49-
50-
5147
@pytest.mark.usefixtures("range_server", "fake_fs")
5248
def test_big_chunk_singleprocess(
5349
range_server: None, fake_fs: FakeFilesystem
@@ -64,3 +60,7 @@ def test_big_chunk_singleprocess(
6460
debug=True,
6561
)
6662
assert reference.read_text() == output.read_text()
63+
64+
65+
# The multiprocess stuff doesn't work well with fake_fs.
66+
# Seems to be fine in the field.

0 commit comments

Comments
 (0)