Skip to content

Commit a685e11

Browse files
committed
feat: add cleanup
1 parent 0e4d8af commit a685e11

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/comfystream/client.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
class ComfyStreamClient:
1616
def __init__(self, max_workers: int = 1, **kwargs):
1717
config = Configuration(**kwargs)
18-
# TODO: Need to handle cleanup for EmbeddedComfyClient if not using async context manager?
1918
self.comfy_client = EmbeddedComfyClient(config, max_workers=max_workers)
2019
self.running_prompts = {} # To be used for cancelling tasks
2120
self.current_prompts = []
@@ -43,6 +42,13 @@ async def run_prompt(self, prompt_index: int):
4342
logger.error(f"Error type: {type(e)}")
4443
raise
4544

45+
async def cleanup(self):
46+
for task in self.running_prompts.values():
47+
await task.cancel()
48+
49+
if self.comfy_client.is_running:
50+
await self.comfy_client.__aexit__()
51+
4652
def put_video_input(self, frame):
4753
if tensor_cache.image_inputs.full():
4854
tensor_cache.image_inputs.get(block=True)

0 commit comments

Comments
 (0)