transition to requests

This commit is contained in:
discountchubbs
2026-08-13 22:11:09 -07:00
parent 198ced6f87
commit 7b441aa0fd
+16 -16
View File
@@ -9,7 +9,7 @@ import asyncio
import os
import time
import aiohttp
import requests
from openpilot.common.params import Params
from openpilot.common.realtime import Ratekeeper
from openpilot.common.swaglog import cloudlog
@@ -63,14 +63,14 @@ class ModelManagerSP:
"""Downloads a file with progress tracking"""
self._download_start_times[model.fileName] = time.monotonic()
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
response.raise_for_status()
total_size = int(response.headers.get("content-length", 0))
bytes_downloaded = 0
with requests.get(url, stream=True, timeout=30) as response: # noqa: ASYNC210
response.raise_for_status()
total_size = int(response.headers.get("content-length", 0))
bytes_downloaded = 0
with open(path, 'wb') as f: # noqa: ASYNC230
async for chunk in response.content.iter_chunked(self._chunk_size): # type: bytes
with open(path, 'wb') as f: # noqa: ASYNC230
for chunk in response.iter_content(chunk_size=self._chunk_size):
if chunk:
f.write(chunk)
bytes_downloaded += len(chunk)
@@ -85,8 +85,8 @@ class ModelManagerSP:
self._sync_artifact_progress(model)
self._report_status()
# Clean up start time after download completes
del self._download_start_times[model.fileName]
# Clean up start time after download completes
del self._download_start_times[model.fileName]
async def _download_chunked(self, base_url: str, base_path: str, artifact) -> None:
from openpilot.common.file_chunker import get_chunk_name, get_manifest_path
@@ -102,12 +102,12 @@ class ModelManagerSP:
chunk_url = get_chunk_name(base_url, i, num_chunks)
chunk_path = get_chunk_name(base_path, i, num_chunks)
chunk_downloaded = 0
async with aiohttp.ClientSession() as session:
async with session.get(chunk_url) as response:
response.raise_for_status()
chunk_size = int(response.headers.get("content-length", 0))
with open(chunk_path, 'wb') as f: # noqa: ASYNC230
async for data in response.content.iter_chunked(self._chunk_size):
with requests.get(chunk_url, stream=True, timeout=30) as response: # noqa: ASYNC210
response.raise_for_status()
chunk_size = int(response.headers.get("content-length", 0))
with open(chunk_path, 'wb') as f: # noqa: ASYNC230
for data in response.iter_content(chunk_size=self._chunk_size):
if data:
f.write(data)
chunk_downloaded += len(data)
if self.params.get("ModelManager_DownloadIndex") is None: