mirror of
https://github.com/Textualize/textual-serve.git
synced 2025-10-17 02:50:37 +03:00
Cleaning up resources
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import asyncio
|
||||
from contextlib import suppress
|
||||
import logging
|
||||
from typing import Tuple
|
||||
|
||||
from textual_serve.app_service import AppService
|
||||
|
||||
log = logging.getLogger("textual-serve")
|
||||
|
||||
DOWNLOAD_TIMEOUT = 4
|
||||
|
||||
DownloadKey = Tuple[str, str]
|
||||
@@ -80,8 +83,16 @@ class DownloadManager:
|
||||
delivery_key: The delivery key to finish the download for.
|
||||
"""
|
||||
download_key = (app_service.app_service_id, delivery_key)
|
||||
queue = self._active_downloads[download_key]
|
||||
try:
|
||||
queue = self._active_downloads[download_key]
|
||||
except KeyError:
|
||||
log.error(f"Download {download_key!r} not found")
|
||||
return
|
||||
|
||||
# Shut down the download queue. Attempt graceful shutdown, but
|
||||
# timeout after DOWNLOAD_TIMEOUT seconds if the queue doesn't clear.
|
||||
await queue.put(None)
|
||||
with suppress(asyncio.TimeoutError):
|
||||
await asyncio.wait_for(queue.join(), timeout=DOWNLOAD_TIMEOUT)
|
||||
|
||||
del self._active_downloads[download_key]
|
||||
|
||||
Reference in New Issue
Block a user