@@ -133,9 +133,6 @@ def __init__(
133133 self ._apify_client : ApifyClientAsync | None = None
134134 self ._local_storage_client : StorageClient | None = None
135135
136- # Set the event manager based on whether the Actor is running on the platform or locally.
137- self ._event_manager : EventManager | None = None
138-
139136 self ._charging_manager : ChargingManagerImplementation | None = None
140137
141138 self ._is_initialized = False
@@ -212,7 +209,7 @@ def config(self) -> Configuration:
212209 return self ._finalize_implicit_configuration ()
213210
214211 def _finalize_implicit_configuration (self ) -> Configuration :
215- """Set implicit configuration in the actor and return it.
212+ """Set implicit configuration in the Actor and return it.
216213
217214 Changing Actor or service_locator configuration after this method was run is not possible.
218215 """
@@ -254,22 +251,20 @@ def _finalize_implicit_local_storage_client(self) -> StorageClient:
254251 )
255252 return self ._local_storage_client
256253
257- @property
254+ @cached_property
258255 def event_manager (self ) -> EventManager :
259256 """The EventManager instance the Actor instance uses."""
260- if not self ._event_manager :
261- self ._event_manager = (
262- ApifyEventManager (
263- configuration = self .config ,
264- persist_state_interval = self .config .persist_state_interval ,
265- )
266- if self .is_at_home ()
267- else LocalEventManager (
268- system_info_interval = self .config .system_info_interval ,
269- persist_state_interval = self .config .persist_state_interval ,
270- )
257+ return (
258+ ApifyEventManager (
259+ configuration = self .config ,
260+ persist_state_interval = self .config .persist_state_interval ,
261+ )
262+ if self .is_at_home ()
263+ else LocalEventManager (
264+ system_info_interval = self .config .system_info_interval ,
265+ persist_state_interval = self .config .persist_state_interval ,
271266 )
272- return self . _event_manager
267+ )
273268
274269 @property
275270 def log (self ) -> logging .Logger :
@@ -350,7 +345,7 @@ async def init(self) -> None:
350345 await self .event_manager .__aenter__ ()
351346 self .log .debug ('Event manager initialized' )
352347
353- await self ._get_charging_manager_implementation .__aenter__ ()
348+ await self .charging_manager_implementation .__aenter__ ()
354349 self .log .debug ('Charging manager initialized' )
355350
356351 self ._is_initialized = True
@@ -394,7 +389,7 @@ async def finalize() -> None:
394389 await self .event_manager .wait_for_all_listeners_to_complete (timeout = event_listeners_timeout )
395390
396391 await self .event_manager .__aexit__ (None , None , None )
397- await self ._get_charging_manager_implementation .__aexit__ (None , None , None )
392+ await self .charging_manager_implementation .__aexit__ (None , None , None )
398393
399394 await asyncio .wait_for (finalize (), cleanup_timeout .total_seconds ())
400395 self ._is_initialized = False
@@ -672,10 +667,10 @@ async def set_value(
672667 def get_charging_manager (self ) -> ChargingManager :
673668 """Retrieve the charging manager to access granular pricing information."""
674669 self ._raise_if_not_initialized ()
675- return self ._get_charging_manager_implementation
670+ return self .charging_manager_implementation
676671
677672 @cached_property
678- def _get_charging_manager_implementation (self ) -> ChargingManagerImplementation :
673+ def charging_manager_implementation (self ) -> ChargingManagerImplementation :
679674 return ChargingManagerImplementation (self .config , self .apify_client )
680675
681676 async def charge (self , event_name : str , count : int = 1 ) -> ChargeResult :
0 commit comments