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
This commit is contained in:
@@ -148,11 +148,14 @@ class AIProcessorAsync:
|
|||||||
CRITICAL FIX (P1-3): Ensures HTTP client cleanup
|
CRITICAL FIX (P1-3): Ensures HTTP client cleanup
|
||||||
"""
|
"""
|
||||||
# Run async processing in sync context
|
# Run async processing in sync context
|
||||||
try:
|
async def _run_with_cleanup():
|
||||||
return asyncio.run(self._process_async(text, context))
|
try:
|
||||||
finally:
|
return await self._process_async(text, context)
|
||||||
# Ensure HTTP client is closed
|
finally:
|
||||||
asyncio.run(self._close_http_client())
|
# 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]]:
|
async def _process_async(self, text: str, context: str) -> Tuple[str, List[AIChange]]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user