Add locks to model_management to prevent multiple copies of the models from being loaded at the same time

This commit is contained in:
doctorpangloss
2024-02-07 15:18:13 -08:00
parent 8e9052c843
commit d9b4607c36
3 changed files with 142 additions and 117 deletions
@@ -1,3 +1,5 @@
import asyncio
import pytest
import torch
@@ -31,3 +33,10 @@ async def test_embedded_comfy():
prompt = sdxl_workflow_with_refiner("test")
outputs = await client.queue_prompt(prompt)
assert outputs["13"]["images"][0]["abs_path"] is not None
@pytest.mark.asyncio
async def test_multithreaded_comfy():
async with EmbeddedComfyClient(max_workers=2) as client:
prompt = sdxl_workflow_with_refiner("test")
outputs_iter = await asyncio.gather(*[client.queue_prompt(prompt) for _ in range(4)])
assert all(outputs["13"]["images"][0]["abs_path"] is not None for outputs in outputs_iter)