5
5
ExperimentConfigurationRequestor ,
6
6
)
7
7
from eppo_client .configuration_store import ConfigurationStore
8
- from eppo_client .constants import MAX_CACHE_ENTRIES
9
8
from eppo_client .http_client import HttpClient , SdkParams
10
9
from eppo_client .models import Flag
11
10
from eppo_client .read_write_lock import ReadWriteLock
@@ -31,18 +30,15 @@ def init(config: Config) -> EppoClient:
31
30
apiKey = config .api_key , sdkName = "python" , sdkVersion = __version__
32
31
)
33
32
http_client = HttpClient (base_url = config .base_url , sdk_params = sdk_params )
34
- config_store : ConfigurationStore [Flag ] = ConfigurationStore (
35
- max_size = MAX_CACHE_ENTRIES
36
- )
33
+ config_store : ConfigurationStore [Flag ] = ConfigurationStore ()
37
34
config_requestor = ExperimentConfigurationRequestor (
38
35
http_client = http_client , config_store = config_store
39
36
)
40
37
assignment_logger = config .assignment_logger
41
38
is_graceful_mode = config .is_graceful_mode
42
39
global __client
43
40
global __lock
44
- try :
45
- __lock .acquire_write ()
41
+ with __lock .writer ():
46
42
if __client :
47
43
# if a client was already initialized, stop the background processes of the old client
48
44
__client ._shutdown ()
@@ -52,8 +48,6 @@ def init(config: Config) -> EppoClient:
52
48
is_graceful_mode = is_graceful_mode ,
53
49
)
54
50
return __client
55
- finally :
56
- __lock .release_write ()
57
51
58
52
59
53
def get_instance () -> EppoClient :
@@ -67,11 +61,8 @@ def get_instance() -> EppoClient:
67
61
"""
68
62
global __client
69
63
global __lock
70
- try :
71
- __lock .acquire_read ()
64
+ with __lock .reader ():
72
65
if __client :
73
66
return __client
74
67
else :
75
68
raise Exception ("init() must be called before get_instance()" )
76
- finally :
77
- __lock .release_read ()
0 commit comments