@@ -101,20 +101,27 @@ def __init__( # pylint: disable=too-many-arguments
101101 self ._labels_enabled = labels_enabled
102102 self ._apis = apis if apis else {}
103103 self ._tasks = tasks if tasks else {}
104- self ._sdk_ready_flag = sdk_ready_flag
104+ self ._sdk_internal_ready_flag = sdk_ready_flag
105+ self ._sdk_ready_flag = threading .Event ()
105106 self ._impressions_manager = impressions_manager
106107
107108 # If we have a ready flag, it means we have sync tasks that need to finish
108109 # before the SDK client becomes ready.
109- if self ._sdk_ready_flag is not None :
110+ if self ._sdk_internal_ready_flag is not None :
110111 self ._status = Status .NOT_INITIALIZED
111112 # add a listener that updates the status to READY once the flag is set.
112- ready_updater = threading .Thread (target = self .block_until_ready )
113+ ready_updater = threading .Thread (target = self ._update_status_when_ready )
113114 ready_updater .setDaemon (True )
114115 ready_updater .start ()
115116 else :
116117 self ._status = Status .READY
117118
119+ def _update_status_when_ready (self ):
120+ """Wait until the sdk is ready and update the status."""
121+ self ._sdk_internal_ready_flag .wait ()
122+ self ._status = Status .READY
123+ self ._sdk_ready_flag .set ()
124+
118125 def _get_storage (self , name ):
119126 """
120127 Return a reference to the specified storage.
@@ -153,14 +160,12 @@ def block_until_ready(self, timeout=None):
153160 :param timeout: Number of seconds to wait (fractions allowed)
154161 :type timeout: int
155162 """
156- if self ._sdk_ready_flag is not None :
163+ if self ._sdk_internal_ready_flag is not None :
157164 ready = self ._sdk_ready_flag .wait (timeout )
158165
159166 if not ready :
160167 raise TimeoutException ('SDK Initialization: time of %d exceeded' % timeout )
161168
162- self ._status = Status .READY
163-
164169 @property
165170 def ready (self ):
166171 """
0 commit comments