MCPcopy Create free account
hub / github.com/apify/crawlee-python / LocalEventManager

Class LocalEventManager

src/crawlee/events/_local_event_manager.py:26–105  ·  view source on GitHub ↗

Event manager for local environments. It extends the `EventManager` to emit `SystemInfo` events at regular intervals. The `LocalEventManager` is intended to be used in local environments, where the system metrics are required managing the `Snapshotter` and `AutoscaledPool`.

Source from the content-addressed store, hash-verified

24
25@docs_group('Event managers')
26class LocalEventManager(EventManager):
27 """Event manager for local environments.
28
29 It extends the `EventManager` to emit `SystemInfo` events at regular intervals. The `LocalEventManager`
30 is intended to be used in local environments, where the system metrics are required managing the `Snapshotter`
31 and `AutoscaledPool`.
32 """
33
34 def __init__(
35 self,
36 system_info_interval: timedelta = timedelta(seconds=1),
37 **event_manager_options: Unpack[EventManagerOptions],
38 ) -> None:
39 """Initialize a new instance.
40
41 In most cases, you should use the `from_config` constructor to create a new instance based on
42 the provided configuration.
43
44 Args:
45 system_info_interval: Interval at which `SystemInfo` events are emitted.
46 event_manager_options: Additional options for the parent class.
47 """
48 self._system_info_interval = system_info_interval
49
50 # Recurring task for emitting system info events.
51 self._emit_system_info_event_rec_task = RecurringTask(
52 func=self._emit_system_info_event,
53 delay=self._system_info_interval,
54 )
55
56 super().__init__(**event_manager_options)
57
58 @classmethod
59 def from_config(cls, config: Configuration | None = None) -> LocalEventManager:
60 """Initialize a new instance based on the provided `Configuration`.
61
62 Args:
63 config: The `Configuration` instance. Uses the global (default) one if not provided.
64 """
65 config = config or Configuration.get_global_configuration()
66
67 return cls(
68 system_info_interval=config.system_info_interval,
69 persist_state_interval=config.persist_state_interval,
70 )
71
72 async def __aenter__(self) -> LocalEventManager:
73 """Initialize the local event manager upon entering the async context.
74
75 It starts emitting system info events at regular intervals.
76 """
77 await super().__aenter__()
78
79 if self._active_ref_count == 1:
80 self._emit_system_info_event_rec_task.start()
81
82 return self
83

Callers 10

get_event_managerMethod · 0.90
event_managerFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by 5

event_managerFunction · 0.72