Skip to content

Commit 83f272b

Browse files
ishaanxguptasreedharsreeram
authored andcommitted
perf(middleware): await background task cancellation on timeout (#786)
1 parent 558d016 commit 83f272b

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

packages/openai-sdk-python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "supermemory-openai-sdk"
7-
version = "1.0.2"
7+
version = "1.0.3"
88
description = "Memory tools for OpenAI function calling with supermemory"
99
readme = "README.md"
1010
license = "MIT"

packages/openai-sdk-python/src/supermemory_openai/middleware.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,12 @@ async def wait_for_background_tasks(self, timeout: Optional[float] = 10.0) -> No
554554
f"Background tasks did not complete within {timeout}s timeout"
555555
)
556556
# Cancel remaining tasks
557-
for task in self._background_tasks:
558-
if not task.done():
559-
task.cancel()
557+
tasks_to_cancel = [task for task in self._background_tasks if not task.done()]
558+
for task in tasks_to_cancel:
559+
task.cancel()
560+
561+
if tasks_to_cancel:
562+
await asyncio.gather(*tasks_to_cancel, return_exceptions=True)
560563
raise
561564

562565
def cancel_background_tasks(self) -> None:

packages/openai-sdk-python/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)