From 476d369bd172f4dc9e927221df9ec2c72967c80a Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Sun, 31 Mar 2024 03:49:57 +0300 Subject: [PATCH] Fixes --- Pipfile | 1 + Pipfile.lock | 27 ++++++++++++++++++++++++++- app/Download.py | 9 ++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Pipfile b/Pipfile index b9eeafc2..1c4587f6 100644 --- a/Pipfile +++ b/Pipfile @@ -14,6 +14,7 @@ python-dotenv = ">=1.0.1" python-magic = ">=0.4.27" debugpy = ">=1.8.1" httpx = "*" +async-timeout = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 2b5921ba..ad8386eb 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b8c580658ddc19c696fab69a5317e66edf477f5560957ab549357b25b1b70212" + "sha256": "dc6e4544c55ad5440a21d9bedd84e11bdcd375c8a3c1ddf7708e8f99e2f7167f" }, "pipfile-spec": 6, "requires": { @@ -130,6 +130,15 @@ ], "version": "==1.4.0" }, + "async-timeout": { + "hashes": [ + "sha256:4640d96be84d82d02ed59ea2b7105a0f7b33abe8703703cd0ab0bf87c427522f", + "sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028" + ], + "index": "pypi", + "markers": "python_version >= '3.7'", + "version": "==4.0.3" + }, "attrs": { "hashes": [ "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30", @@ -392,6 +401,14 @@ "markers": "python_version >= '3.8'", "version": "==1.8.1" }, + "exceptiongroup": { + "hashes": [ + "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14", + "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68" + ], + "markers": "python_version < '3.11'", + "version": "==1.2.0" + }, "frozenlist": { "hashes": [ "sha256:04ced3e6a46b4cfffe20f9ae482818e34eba9b5fb0ce4056e4cc9b6e212d09b7", @@ -740,6 +757,14 @@ "markers": "python_version >= '3.7'", "version": "==1.3.1" }, + "typing-extensions": { + "hashes": [ + "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475", + "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb" + ], + "markers": "python_version < '3.11'", + "version": "==4.10.0" + }, "tzlocal": { "hashes": [ "sha256:49816ef2fe65ea8ac19d19aa7a1ae0551c834303d5014c6d5a62e4cbda8047b8", diff --git a/app/Download.py b/app/Download.py index 4d1633f0..85ced62c 100644 --- a/app/Download.py +++ b/app/Download.py @@ -226,8 +226,7 @@ class Download: LOG.info(f"Closing download process: '{procId}'.") try: if 'update_task' in self.__dict__ and self.update_task.done() is False: - self.status_queue.put(Terminator(), timeout=3) - LOG.debug(f"Closed status queue: '{procId}'.") + self.update_task.cancel() except Exception as e: LOG.error(f"Failed to close status queue: '{procId}'. {e}") pass @@ -307,7 +306,11 @@ class Download: Update status of download task and notify the client. """ while True: - self.update_task = asyncio.get_running_loop().run_in_executor(None, self.status_queue.get) + try: + self.update_task = asyncio.get_running_loop().run_in_executor(None, self.status_queue.get) + except asyncio.CancelledError: + LOG.debug(f'Closing progress update for: {self.info._id=}.') + return status = await self.update_task