alma-memory 0.5.0__py3-none-any.whl → 0.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alma/__init__.py +296 -194
- alma/compression/__init__.py +33 -0
- alma/compression/pipeline.py +980 -0
- alma/confidence/__init__.py +47 -47
- alma/confidence/engine.py +540 -540
- alma/confidence/types.py +351 -351
- alma/config/loader.py +157 -157
- alma/consolidation/__init__.py +23 -23
- alma/consolidation/engine.py +678 -678
- alma/consolidation/prompts.py +84 -84
- alma/core.py +1189 -322
- alma/domains/__init__.py +30 -30
- alma/domains/factory.py +359 -359
- alma/domains/schemas.py +448 -448
- alma/domains/types.py +272 -272
- alma/events/__init__.py +75 -75
- alma/events/emitter.py +285 -284
- alma/events/storage_mixin.py +246 -246
- alma/events/types.py +126 -126
- alma/events/webhook.py +425 -425
- alma/exceptions.py +49 -49
- alma/extraction/__init__.py +31 -31
- alma/extraction/auto_learner.py +265 -264
- alma/extraction/extractor.py +420 -420
- alma/graph/__init__.py +106 -81
- alma/graph/backends/__init__.py +32 -18
- alma/graph/backends/kuzu.py +624 -0
- alma/graph/backends/memgraph.py +432 -0
- alma/graph/backends/memory.py +236 -236
- alma/graph/backends/neo4j.py +417 -417
- alma/graph/base.py +159 -159
- alma/graph/extraction.py +198 -198
- alma/graph/store.py +860 -860
- alma/harness/__init__.py +35 -35
- alma/harness/base.py +386 -386
- alma/harness/domains.py +705 -705
- alma/initializer/__init__.py +37 -37
- alma/initializer/initializer.py +418 -418
- alma/initializer/types.py +250 -250
- alma/integration/__init__.py +62 -62
- alma/integration/claude_agents.py +444 -432
- alma/integration/helena.py +423 -423
- alma/integration/victor.py +471 -471
- alma/learning/__init__.py +101 -86
- alma/learning/decay.py +878 -0
- alma/learning/forgetting.py +1446 -1446
- alma/learning/heuristic_extractor.py +390 -390
- alma/learning/protocols.py +374 -374
- alma/learning/validation.py +346 -346
- alma/mcp/__init__.py +123 -45
- alma/mcp/__main__.py +156 -156
- alma/mcp/resources.py +122 -122
- alma/mcp/server.py +955 -591
- alma/mcp/tools.py +3254 -511
- alma/observability/__init__.py +91 -0
- alma/observability/config.py +302 -0
- alma/observability/guidelines.py +170 -0
- alma/observability/logging.py +424 -0
- alma/observability/metrics.py +583 -0
- alma/observability/tracing.py +440 -0
- alma/progress/__init__.py +21 -21
- alma/progress/tracker.py +607 -607
- alma/progress/types.py +250 -250
- alma/retrieval/__init__.py +134 -53
- alma/retrieval/budget.py +525 -0
- alma/retrieval/cache.py +1304 -1061
- alma/retrieval/embeddings.py +202 -202
- alma/retrieval/engine.py +850 -366
- alma/retrieval/modes.py +365 -0
- alma/retrieval/progressive.py +560 -0
- alma/retrieval/scoring.py +344 -344
- alma/retrieval/trust_scoring.py +637 -0
- alma/retrieval/verification.py +797 -0
- alma/session/__init__.py +19 -19
- alma/session/manager.py +442 -399
- alma/session/types.py +288 -288
- alma/storage/__init__.py +101 -61
- alma/storage/archive.py +233 -0
- alma/storage/azure_cosmos.py +1259 -1048
- alma/storage/base.py +1083 -525
- alma/storage/chroma.py +1443 -1443
- alma/storage/constants.py +103 -0
- alma/storage/file_based.py +614 -619
- alma/storage/migrations/__init__.py +21 -0
- alma/storage/migrations/base.py +321 -0
- alma/storage/migrations/runner.py +323 -0
- alma/storage/migrations/version_stores.py +337 -0
- alma/storage/migrations/versions/__init__.py +11 -0
- alma/storage/migrations/versions/v1_0_0.py +373 -0
- alma/storage/migrations/versions/v1_1_0_workflow_context.py +551 -0
- alma/storage/pinecone.py +1080 -1080
- alma/storage/postgresql.py +1948 -1452
- alma/storage/qdrant.py +1306 -1306
- alma/storage/sqlite_local.py +3041 -1358
- alma/testing/__init__.py +46 -0
- alma/testing/factories.py +301 -0
- alma/testing/mocks.py +389 -0
- alma/types.py +292 -264
- alma/utils/__init__.py +19 -0
- alma/utils/tokenizer.py +521 -0
- alma/workflow/__init__.py +83 -0
- alma/workflow/artifacts.py +170 -0
- alma/workflow/checkpoint.py +311 -0
- alma/workflow/context.py +228 -0
- alma/workflow/outcomes.py +189 -0
- alma/workflow/reducers.py +393 -0
- {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/METADATA +244 -72
- alma_memory-0.7.0.dist-info/RECORD +112 -0
- alma_memory-0.5.0.dist-info/RECORD +0 -76
- {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/WHEEL +0 -0
- {alma_memory-0.5.0.dist-info → alma_memory-0.7.0.dist-info}/top_level.txt +0 -0
alma/events/emitter.py
CHANGED
|
@@ -1,284 +1,285 @@
|
|
|
1
|
-
"""
|
|
2
|
-
ALMA Event Emitter.
|
|
3
|
-
|
|
4
|
-
Provides a pub/sub mechanism for memory events, allowing components
|
|
5
|
-
and external systems to subscribe to and receive notifications about
|
|
6
|
-
memory changes.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
import asyncio
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
from
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
emitter.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
self.
|
|
55
|
-
self.
|
|
56
|
-
self.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
self.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
callbacks
|
|
210
|
-
callbacks
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
self.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
self.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
1
|
+
"""
|
|
2
|
+
ALMA Event Emitter.
|
|
3
|
+
|
|
4
|
+
Provides a pub/sub mechanism for memory events, allowing components
|
|
5
|
+
and external systems to subscribe to and receive notifications about
|
|
6
|
+
memory changes.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import inspect
|
|
11
|
+
import logging
|
|
12
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
13
|
+
from typing import Awaitable, Callable, Dict, List, Optional, Union
|
|
14
|
+
|
|
15
|
+
from alma.events.types import MemoryEvent, MemoryEventType
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
# Type aliases for callbacks
|
|
20
|
+
SyncCallback = Callable[[MemoryEvent], None]
|
|
21
|
+
AsyncCallback = Callable[[MemoryEvent], Awaitable[None]]
|
|
22
|
+
EventCallback = Union[SyncCallback, AsyncCallback]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class EventEmitter:
|
|
26
|
+
"""
|
|
27
|
+
Event emitter for memory system events.
|
|
28
|
+
|
|
29
|
+
Supports both synchronous and asynchronous callbacks, with options
|
|
30
|
+
to subscribe to specific event types or all events.
|
|
31
|
+
|
|
32
|
+
The emitter is designed to be non-blocking - callbacks are executed
|
|
33
|
+
in a way that doesn't slow down the main storage operations.
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
```python
|
|
37
|
+
emitter = EventEmitter()
|
|
38
|
+
|
|
39
|
+
def on_created(event: MemoryEvent):
|
|
40
|
+
print(f"Memory created: {event.memory_id}")
|
|
41
|
+
|
|
42
|
+
emitter.subscribe(MemoryEventType.CREATED, on_created)
|
|
43
|
+
emitter.emit(event)
|
|
44
|
+
```
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, max_workers: int = 4):
|
|
48
|
+
"""
|
|
49
|
+
Initialize the event emitter.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
max_workers: Maximum number of worker threads for async callback execution
|
|
53
|
+
"""
|
|
54
|
+
self._subscribers: Dict[MemoryEventType, List[EventCallback]] = {}
|
|
55
|
+
self._global_subscribers: List[EventCallback] = []
|
|
56
|
+
self._executor = ThreadPoolExecutor(max_workers=max_workers)
|
|
57
|
+
self._enabled = True
|
|
58
|
+
|
|
59
|
+
def subscribe(
|
|
60
|
+
self,
|
|
61
|
+
event_type: MemoryEventType,
|
|
62
|
+
callback: EventCallback,
|
|
63
|
+
) -> None:
|
|
64
|
+
"""
|
|
65
|
+
Subscribe to a specific event type.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
event_type: The type of event to subscribe to
|
|
69
|
+
callback: Function to call when event occurs (sync or async)
|
|
70
|
+
"""
|
|
71
|
+
if event_type not in self._subscribers:
|
|
72
|
+
self._subscribers[event_type] = []
|
|
73
|
+
|
|
74
|
+
if callback not in self._subscribers[event_type]:
|
|
75
|
+
self._subscribers[event_type].append(callback)
|
|
76
|
+
callback_name = getattr(callback, "__name__", repr(callback))
|
|
77
|
+
logger.debug(f"Subscribed to {event_type.value}: {callback_name}")
|
|
78
|
+
|
|
79
|
+
def subscribe_all(self, callback: EventCallback) -> None:
|
|
80
|
+
"""
|
|
81
|
+
Subscribe to all events.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
callback: Function to call for any event
|
|
85
|
+
"""
|
|
86
|
+
if callback not in self._global_subscribers:
|
|
87
|
+
self._global_subscribers.append(callback)
|
|
88
|
+
callback_name = getattr(callback, "__name__", repr(callback))
|
|
89
|
+
logger.debug(f"Subscribed to all events: {callback_name}")
|
|
90
|
+
|
|
91
|
+
def unsubscribe(
|
|
92
|
+
self,
|
|
93
|
+
event_type: MemoryEventType,
|
|
94
|
+
callback: EventCallback,
|
|
95
|
+
) -> bool:
|
|
96
|
+
"""
|
|
97
|
+
Unsubscribe from a specific event type.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
event_type: The event type to unsubscribe from
|
|
101
|
+
callback: The callback to remove
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
True if callback was removed, False if not found
|
|
105
|
+
"""
|
|
106
|
+
if event_type in self._subscribers:
|
|
107
|
+
try:
|
|
108
|
+
self._subscribers[event_type].remove(callback)
|
|
109
|
+
callback_name = getattr(callback, "__name__", repr(callback))
|
|
110
|
+
logger.debug(f"Unsubscribed from {event_type.value}: {callback_name}")
|
|
111
|
+
return True
|
|
112
|
+
except ValueError:
|
|
113
|
+
pass
|
|
114
|
+
return False
|
|
115
|
+
|
|
116
|
+
def unsubscribe_all(self, callback: EventCallback) -> bool:
|
|
117
|
+
"""
|
|
118
|
+
Unsubscribe a callback from all events.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
callback: The callback to remove
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
True if callback was removed, False if not found
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
self._global_subscribers.remove(callback)
|
|
128
|
+
callback_name = getattr(callback, "__name__", repr(callback))
|
|
129
|
+
logger.debug(f"Unsubscribed from all events: {callback_name}")
|
|
130
|
+
return True
|
|
131
|
+
except ValueError:
|
|
132
|
+
return False
|
|
133
|
+
|
|
134
|
+
def has_subscribers(self, event_type: Optional[MemoryEventType] = None) -> bool:
|
|
135
|
+
"""
|
|
136
|
+
Check if there are any subscribers.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
event_type: Optional specific event type to check
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
True if there are subscribers
|
|
143
|
+
"""
|
|
144
|
+
if event_type is None:
|
|
145
|
+
return bool(self._global_subscribers) or any(
|
|
146
|
+
bool(subs) for subs in self._subscribers.values()
|
|
147
|
+
)
|
|
148
|
+
return bool(self._subscribers.get(event_type)) or bool(self._global_subscribers)
|
|
149
|
+
|
|
150
|
+
def emit(self, event: MemoryEvent) -> None:
|
|
151
|
+
"""
|
|
152
|
+
Emit an event to all matching subscribers (non-blocking).
|
|
153
|
+
|
|
154
|
+
Callbacks are executed in a thread pool to avoid blocking
|
|
155
|
+
the main thread. Any exceptions in callbacks are logged
|
|
156
|
+
but do not propagate.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
event: The event to emit
|
|
160
|
+
"""
|
|
161
|
+
if not self._enabled:
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
callbacks = self._get_callbacks(event.event_type)
|
|
165
|
+
if not callbacks:
|
|
166
|
+
return
|
|
167
|
+
|
|
168
|
+
# Execute callbacks in thread pool (non-blocking)
|
|
169
|
+
for callback in callbacks:
|
|
170
|
+
self._executor.submit(self._safe_call, callback, event)
|
|
171
|
+
|
|
172
|
+
async def emit_async(self, event: MemoryEvent) -> None:
|
|
173
|
+
"""
|
|
174
|
+
Emit an event to all matching subscribers asynchronously.
|
|
175
|
+
|
|
176
|
+
For async callbacks, awaits them directly. For sync callbacks,
|
|
177
|
+
runs them in the executor.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
event: The event to emit
|
|
181
|
+
"""
|
|
182
|
+
if not self._enabled:
|
|
183
|
+
return
|
|
184
|
+
|
|
185
|
+
callbacks = self._get_callbacks(event.event_type)
|
|
186
|
+
if not callbacks:
|
|
187
|
+
return
|
|
188
|
+
|
|
189
|
+
tasks = []
|
|
190
|
+
for callback in callbacks:
|
|
191
|
+
if inspect.iscoroutinefunction(callback):
|
|
192
|
+
tasks.append(self._safe_call_async(callback, event))
|
|
193
|
+
else:
|
|
194
|
+
# Run sync callbacks in executor
|
|
195
|
+
loop = asyncio.get_event_loop()
|
|
196
|
+
tasks.append(
|
|
197
|
+
loop.run_in_executor(
|
|
198
|
+
self._executor,
|
|
199
|
+
self._safe_call,
|
|
200
|
+
callback,
|
|
201
|
+
event,
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if tasks:
|
|
206
|
+
await asyncio.gather(*tasks, return_exceptions=True)
|
|
207
|
+
|
|
208
|
+
def _get_callbacks(self, event_type: MemoryEventType) -> List[EventCallback]:
|
|
209
|
+
"""Get all callbacks for an event type."""
|
|
210
|
+
callbacks = list(self._global_subscribers)
|
|
211
|
+
callbacks.extend(self._subscribers.get(event_type, []))
|
|
212
|
+
return callbacks
|
|
213
|
+
|
|
214
|
+
def _safe_call(self, callback: SyncCallback, event: MemoryEvent) -> None:
|
|
215
|
+
"""Safely call a sync callback, catching exceptions."""
|
|
216
|
+
try:
|
|
217
|
+
callback(event)
|
|
218
|
+
except Exception as e:
|
|
219
|
+
callback_name = getattr(callback, "__name__", repr(callback))
|
|
220
|
+
logger.error(
|
|
221
|
+
f"Error in event callback {callback_name}: {e}",
|
|
222
|
+
exc_info=True,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
async def _safe_call_async(
|
|
226
|
+
self,
|
|
227
|
+
callback: AsyncCallback,
|
|
228
|
+
event: MemoryEvent,
|
|
229
|
+
) -> None:
|
|
230
|
+
"""Safely call an async callback, catching exceptions."""
|
|
231
|
+
try:
|
|
232
|
+
await callback(event)
|
|
233
|
+
except Exception as e:
|
|
234
|
+
callback_name = getattr(callback, "__name__", repr(callback))
|
|
235
|
+
logger.error(
|
|
236
|
+
f"Error in async event callback {callback_name}: {e}",
|
|
237
|
+
exc_info=True,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
def enable(self) -> None:
|
|
241
|
+
"""Enable event emission."""
|
|
242
|
+
self._enabled = True
|
|
243
|
+
|
|
244
|
+
def disable(self) -> None:
|
|
245
|
+
"""Disable event emission (events will be silently dropped)."""
|
|
246
|
+
self._enabled = False
|
|
247
|
+
|
|
248
|
+
def clear(self) -> None:
|
|
249
|
+
"""Remove all subscribers."""
|
|
250
|
+
self._subscribers.clear()
|
|
251
|
+
self._global_subscribers.clear()
|
|
252
|
+
|
|
253
|
+
def shutdown(self) -> None:
|
|
254
|
+
"""Shutdown the executor and clear subscribers."""
|
|
255
|
+
self.clear()
|
|
256
|
+
self._executor.shutdown(wait=False)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
# Global emitter instance (singleton pattern)
|
|
260
|
+
_emitter: Optional[EventEmitter] = None
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def get_emitter() -> EventEmitter:
|
|
264
|
+
"""
|
|
265
|
+
Get the global event emitter instance.
|
|
266
|
+
|
|
267
|
+
Returns:
|
|
268
|
+
The singleton EventEmitter instance
|
|
269
|
+
"""
|
|
270
|
+
global _emitter
|
|
271
|
+
if _emitter is None:
|
|
272
|
+
_emitter = EventEmitter()
|
|
273
|
+
return _emitter
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def reset_emitter() -> None:
|
|
277
|
+
"""
|
|
278
|
+
Reset the global emitter (mainly for testing).
|
|
279
|
+
|
|
280
|
+
Creates a fresh emitter instance, clearing all subscriptions.
|
|
281
|
+
"""
|
|
282
|
+
global _emitter
|
|
283
|
+
if _emitter is not None:
|
|
284
|
+
_emitter.shutdown()
|
|
285
|
+
_emitter = EventEmitter()
|