Remove unnecessary lock

This commit is contained in:
Darren Burns
2024-08-13 10:24:38 +01:00
parent 15e67c89db
commit fa19aeef3a

View File

@@ -1,7 +1,6 @@
from __future__ import annotations
import asyncio
from contextlib import suppress
from dataclasses import dataclass, field
import logging
from typing import AsyncGenerator, TYPE_CHECKING
@@ -36,7 +35,6 @@ class DownloadManager:
"""
def __init__(self):
self._active_downloads_lock = asyncio.Lock()
self._active_downloads: dict[str, Download] = {}
"""A dictionary of active downloads.
@@ -66,7 +64,6 @@ class DownloadManager:
file_name: The name of the file to download.
open_method: The method to open the file with.
"""
async with self._active_downloads_lock:
self._active_downloads[delivery_key] = Download(
app_service,
delivery_key,
@@ -102,11 +99,6 @@ class DownloadManager:
if not chunk:
# Empty chunk - the app process has finished sending the file.
incoming_chunks.task_done()
with suppress(asyncio.TimeoutError):
await asyncio.wait_for(
download.incoming_chunks.join(), timeout=DOWNLOAD_TIMEOUT
)
async with self._active_downloads_lock:
del self._active_downloads[delivery_key]
break
else:
@@ -129,14 +121,11 @@ class DownloadManager:
Args:
delivery_key: The delivery key to get the app service for.
"""
async with self._active_downloads_lock:
for key in self._active_downloads.keys():
if key == delivery_key:
return self._active_downloads[key].app_service
else:
raise ValueError(
f"No active download for delivery key {delivery_key!r}"
)
raise ValueError(f"No active download for delivery key {delivery_key!r}")
async def get_download_metadata(self, delivery_key: str) -> Download:
"""Get the metadata for a download.
@@ -144,5 +133,4 @@ class DownloadManager:
Args:
delivery_key: The delivery key to get the metadata for.
"""
async with self._active_downloads_lock:
return self._active_downloads[delivery_key]