Skip to content

Commit 99254da

Browse files
authored
Make Catalog.load thread-safe (#228)
1 parent de63f51 commit 99254da

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/gpuhunt/_internal/catalog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def query(
114114
if self.auto_reload and (
115115
self.loaded_at is None or time.monotonic() - self.loaded_at > RELOAD_INTERVAL
116116
):
117-
self.load()
117+
self._load()
118118

119119
query_filter = QueryFilter(
120120
provider=[provider] if isinstance(provider, str) else provider,
@@ -183,11 +183,15 @@ def query(
183183

184184
def load(self, version: Optional[str] = None):
185185
"""
186-
Fetch the catalog from the S3 bucket
186+
Fetch the catalog from the S3 bucket. Thread-safe.
187187
188188
Args:
189189
version: specific version of the catalog to download. If not specified, the latest version will be used
190190
"""
191+
with self._load_lock:
192+
self._load(version)
193+
194+
def _load(self, version: Optional[str] = None):
191195
catalog_url = os.getenv("GPUHUNT_CATALOG_URL")
192196
if catalog_url is None:
193197
if version is None:

0 commit comments

Comments
 (0)