MCPcopy Create free account
hub / github.com/BIT-DataLab/Edit-Banana / Sam3ServicePool

Class Sam3ServicePool

sam3_service/client.py:45–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class Sam3ServicePool:
46 def __init__(self, endpoints: List[str], timeout: int = 120) -> None:
47 if len(endpoints) == 0:
48 raise ValueError("At least one endpoint is required")
49 self.clients = [Sam3ServiceClient(url, timeout=timeout) for url in endpoints]
50 self._lock = threading.Lock()
51 self._cursor = itertools.cycle(range(len(self.clients)))
52
53 def predict(self, *args, **kwargs) -> Dict:
54 with self._lock:
55 client_index = next(self._cursor)
56 return self.clients[client_index].predict(*args, **kwargs)
57
58 def health(self) -> Dict[str, bool]:
59 status: Dict[str, bool] = {}
60 for client in self.clients:
61 try:
62 status[client.base_url] = client.health()
63 except Exception:
64 status[client.base_url] = False
65 return status

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected