mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-12 23:01:07 +00:00
fix httpx client resource leak with proper async cleanup
This commit is contained in:
parent
a185dc252b
commit
2e8c19034a
2 changed files with 17 additions and 0 deletions
|
|
@ -42,6 +42,10 @@ class MemoryClient:
|
|||
|
||||
async def __aexit__(self, *args):
|
||||
"""Async context manager exit - cleanup client."""
|
||||
await self.aclose()
|
||||
|
||||
async def aclose(self):
|
||||
"""Close the httpx client."""
|
||||
if self._client:
|
||||
await self._client.aclose()
|
||||
self._client = None
|
||||
|
|
|
|||
|
|
@ -105,6 +105,11 @@ class SupermemoryOpenAIWrapper:
|
|||
self._executor.shutdown(wait=True)
|
||||
self._executor = None
|
||||
|
||||
async def aclose(self) -> None:
|
||||
"""Async cleanup of resources."""
|
||||
await self.memory_client.aclose()
|
||||
self.close()
|
||||
|
||||
def __enter__(self):
|
||||
"""Context manager entry."""
|
||||
return self
|
||||
|
|
@ -113,6 +118,14 @@ class SupermemoryOpenAIWrapper:
|
|||
"""Context manager exit - cleanup resources."""
|
||||
self.close()
|
||||
|
||||
async def __aenter__(self):
|
||||
"""Async context manager entry."""
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *args):
|
||||
"""Async context manager exit - cleanup resources."""
|
||||
await self.aclose()
|
||||
|
||||
async def _add_memory_if_needed(self, messages: List[ChatCompletionMessageParam]) -> None:
|
||||
"""Add conversation to memory if configured to do so."""
|
||||
if self.options.add_memory != "always":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue