Skip to content

Commit 2074959

Browse files
author
Stanley Opara
committed
make refresh code a daemon thread
Signed-off-by: Stanley Opara <a-sopara@expediagroup.com>
1 parent c05b0db commit 2074959

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sdk/python/feast/infra/registry/caching_registry.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import atexit
12
import logging
23
import threading
34
from abc import abstractmethod
@@ -33,7 +34,7 @@ def __init__(
3334
)
3435
self.allow_async_cache = allow_async_cache
3536
if allow_async_cache:
36-
threading.Timer(cache_ttl_seconds, self.refresh).start()
37+
self._start_async_refresh(cache_ttl_seconds)
3738

3839
@abstractmethod
3940
def _get_data_source(self, name: str, project: str) -> DataSource:
@@ -312,3 +313,12 @@ def _refresh_cached_registry_if_necessary(self):
312313
if expired:
313314
logger.info("Registry cache expired, so refreshing")
314315
self.refresh()
316+
317+
def _start_async_refresh(self, cache_ttl_seconds):
318+
self.registry_refresh_thread = threading.Timer(cache_ttl_seconds, self.refresh)
319+
self.registry_refresh_thread.setDaemon(True)
320+
self.registry_refresh_thread.start()
321+
atexit.register(self._exit_handler)
322+
323+
def _exit_handler(self):
324+
self.registry_refresh_thread.cancel()

0 commit comments

Comments
 (0)