@@ -91,7 +91,7 @@ def __init__( # pylint: disable=too-many-arguments
9191 recorder ,
9292 sync_manager = None ,
9393 sdk_ready_flag = None ,
94- should_handle_post_fork = False ,
94+ preforked_initialization = False ,
9595 ):
9696 """
9797 Class constructor.
@@ -108,25 +108,27 @@ def __init__( # pylint: disable=too-many-arguments
108108 :type sdk_ready_flag: threading.Event
109109 :param recorder: StatsRecorder instance
110110 :type recorder: StatsRecorder
111+ :param preforked_initialization: Whether should be instantiated as preforked or not.
112+ :type preforked_initialization: bool
111113 """
112114 self ._apikey = apikey
113115 self ._storages = storages
114116 self ._labels_enabled = labels_enabled
115117 self ._sync_manager = sync_manager
116118 self ._sdk_internal_ready_flag = sdk_ready_flag
117119 self ._recorder = recorder
118- self ._should_handle_post_fork = should_handle_post_fork
119- self ._start_ready_updater ()
120+ self ._preforked_initialization = preforked_initialization
121+ self ._start_status_updater ()
120122
121- def _start_ready_updater (self ):
123+ def _start_status_updater (self ):
122124 """
123- Perform ready updater
125+ Perform status updater
124126 """
125- # If we have a ready flag, it means we have sync tasks that need to finish
126- # before the SDK client becomes ready.
127- if self ._should_handle_post_fork :
127+ if self ._preforked_initialization :
128128 self ._status = Status .WAITING_FORK
129129 return
130+ # If we have a ready flag, it means we have sync tasks that need to finish
131+ # before the SDK client becomes ready.
130132 if self ._sdk_internal_ready_flag is not None :
131133 self ._sdk_ready_flag = threading .Event ()
132134 self ._status = Status .NOT_INITIALIZED
@@ -243,35 +245,37 @@ def destroyed(self):
243245 """
244246 return self ._status == Status .DESTROYED
245247
246- @property
247- def waiting_fork (self ):
248+ def _waiting_fork (self ):
248249 """
249- Return whether the factory is waiting for fork recreation or not.
250+ Return whether the factory is waiting to be recreated by forking or not.
250251
251- :return: True if the factory is waiting for fork recreation . False otherwise.
252+ :return: True if the factory is waiting to be recreated by forking . False otherwise.
252253 :rtype: bool
253254 """
254255 return self ._status == Status .WAITING_FORK
255256
256257 def handle_post_fork (self ):
257258 """
258- Function capable to re-synchronize splits data on fork processes .
259+ Function in charge of starting periodic/realtime synchronization after a fork .
259260 """
260- if not self .waiting_fork :
261+ if not self ._waiting_fork () :
261262 _LOGGER .warning ('Cannot call handle_post_fork' )
262263 return
263- self ._should_handle_post_fork = False # Reset for updater
264264 self ._sync_manager .recreate ()
265265 sdk_ready_flag = threading .Event ()
266266 self ._sdk_internal_ready_flag = sdk_ready_flag
267267 self ._sync_manager ._ready_flag = sdk_ready_flag
268+ self ._get_storage ('telemetry' ).clear ()
269+ self ._get_storage ('impressions' ).clear ()
270+ self ._get_storage ('events' ).clear ()
268271 initialization_thread = threading .Thread (
269272 target = self ._sync_manager .start ,
270273 name = "SDKInitializer" ,
271274 )
272275 initialization_thread .setDaemon (True )
273276 initialization_thread .start ()
274- self ._start_ready_updater ()
277+ self ._preforked_initialization = False # reset for status updater
278+ self ._start_status_updater ()
275279
276280
277281def _wrap_impression_listener (listener , metadata ):
@@ -360,9 +364,9 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
360364
361365 synchronizer = Synchronizer (synchronizers , tasks )
362366
363- should_handle_post_fork = cfg .get ('shouldHandlePostFork ' , False )
367+ preforked_initialization = cfg .get ('preforkedInitialization ' , False )
364368
365- sdk_ready_flag = threading .Event () if not should_handle_post_fork else None
369+ sdk_ready_flag = threading .Event () if not preforked_initialization else None
366370 manager = Manager (sdk_ready_flag , synchronizer , apis ['auth' ], cfg ['streamingEnabled' ],
367371 streaming_api_base_url )
368372
@@ -376,10 +380,11 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
376380 storages ['impressions' ],
377381 )
378382
379- if should_handle_post_fork :
383+ if preforked_initialization :
380384 synchronizer .sync_all ()
385+ synchronizer ._split_synchronizers ._segment_sync .shutdown ()
381386 return SplitFactory (api_key , storages , cfg ['labelsEnabled' ],
382- recorder , manager , should_handle_post_fork = should_handle_post_fork )
387+ recorder , manager , preforked_initialization = preforked_initialization )
383388
384389 initialization_thread = threading .Thread (target = manager .start , name = "SDKInitializer" )
385390 initialization_thread .setDaemon (True )
0 commit comments