prevent the Download queue from back pressuring the event loop
This commit is contained in:
parent
388ed0bf9d
commit
a584ffcfd6
1 changed files with 14 additions and 8 deletions
|
|
@ -720,17 +720,23 @@ class DownloadQueue(metaclass=Singleton):
|
||||||
if entry.started() or entry.is_cancelled():
|
if entry.started() or entry.is_cancelled():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
asyncio.create_task(
|
if entry.is_live:
|
||||||
self._download_temp(_id, entry) if entry.is_live else self._download(_id, entry)
|
task = asyncio.create_task(self._download_live(_id, entry))
|
||||||
).add_done_callback(self._handle_task_exception)
|
task.add_done_callback(self._handle_task_exception)
|
||||||
|
else:
|
||||||
|
await self.workers.acquire()
|
||||||
|
|
||||||
|
task = asyncio.create_task(self._download_file(_id, entry))
|
||||||
|
|
||||||
|
def _release_semaphore(t: asyncio.Task):
|
||||||
|
self.workers.release()
|
||||||
|
self._handle_task_exception(t)
|
||||||
|
|
||||||
|
task.add_done_callback(_release_semaphore)
|
||||||
|
|
||||||
await asyncio.sleep(0.5)
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
async def _download(self, _id: str, entry: Download) -> None:
|
async def _download_live(self, _id: str, entry: Download) -> None:
|
||||||
async with self.workers:
|
|
||||||
await self._download_file(_id, entry)
|
|
||||||
|
|
||||||
async def _download_temp(self, _id: str, entry: Download) -> None:
|
|
||||||
LOG.info(f"Creating temporary worker for entry '{entry.info.name()}'.")
|
LOG.info(f"Creating temporary worker for entry '{entry.info.name()}'.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue