From 77132d8ce3c8907900cd3a2785d18b623614cea1 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Mon, 11 Nov 2024 20:31:18 +0300 Subject: [PATCH] try another way to stop a leak --- selfprivacy_api/graphql/subscriptions/logs.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/selfprivacy_api/graphql/subscriptions/logs.py b/selfprivacy_api/graphql/subscriptions/logs.py index e3715bb..dc7a65b 100644 --- a/selfprivacy_api/graphql/subscriptions/logs.py +++ b/selfprivacy_api/graphql/subscriptions/logs.py @@ -21,12 +21,17 @@ async def log_stream() -> AsyncGenerator[LogEntry, None]: asyncio.get_event_loop().add_reader(j, lambda: asyncio.ensure_future(callback())) - while True: - entry = await queue.get() - try: - yield LogEntry(entry) - except Exception: - asyncio.get_event_loop().remove_reader(j) - j.close() - return - queue.task_done() + try: + while True: + entry = await queue.get() + try: + yield LogEntry(entry) + except Exception: + asyncio.get_event_loop().remove_reader(j) + j.close() + return + queue.task_done() + except asyncio.CancelledError: + asyncio.get_event_loop().remove_reader(j) + j.close() + return