From dbcb53a3760bf0049bb4c4424d6fdffa4139b9ef Mon Sep 17 00:00:00 2001 From: daymade Date: Sat, 20 Dec 2025 23:29:28 +0800 Subject: [PATCH] Fix RuntimeError: Event loop is closed - Move HTTP client cleanup into the same async context - Prevents 'Event loop is closed' error when closing HTTP client - Ensures proper resource cleanup in the same event loop --- transcript-fixer/scripts/core/ai_processor_async.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/transcript-fixer/scripts/core/ai_processor_async.py b/transcript-fixer/scripts/core/ai_processor_async.py index d05f2d7..a225126 100644 --- a/transcript-fixer/scripts/core/ai_processor_async.py +++ b/transcript-fixer/scripts/core/ai_processor_async.py @@ -148,11 +148,14 @@ class AIProcessorAsync: CRITICAL FIX (P1-3): Ensures HTTP client cleanup """ # Run async processing in sync context - try: - return asyncio.run(self._process_async(text, context)) - finally: - # Ensure HTTP client is closed - asyncio.run(self._close_http_client()) + async def _run_with_cleanup(): + try: + return await self._process_async(text, context) + finally: + # Ensure HTTP client is closed in the same event loop + await self._close_http_client() + + return asyncio.run(_run_with_cleanup()) async def _process_async(self, text: str, context: str) -> Tuple[str, List[AIChange]]: """