-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path__init__.py
More file actions
43 lines (30 loc) · 1.35 KB
/
Copy path__init__.py
File metadata and controls
43 lines (30 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
43
# Global event bus instance - uses SqliteEventBus for cross-process functionality
from typing import Any, Callable
from eval_protocol.event_bus.event_bus import EventBus
from eval_protocol.event_bus.sqlite_event_bus_database import (
DatabaseCorruptedError,
check_and_repair_database,
SQLITE_HARDENED_PRAGMAS,
)
def _get_default_event_bus():
from eval_protocol.event_bus.sqlite_event_bus import SqliteEventBus
return SqliteEventBus()
# Lazy property that creates the event bus only when accessed
class _LazyEventBus(EventBus):
def __init__(self):
self._event_bus: EventBus | None = None
def _get_event_bus(self):
if self._event_bus is None:
self._event_bus = _get_default_event_bus()
return self._event_bus
def subscribe(self, callback: Callable[[str, Any], None]) -> None:
return self._get_event_bus().subscribe(callback)
def unsubscribe(self, callback: Callable[[str, Any], None]) -> None:
return self._get_event_bus().unsubscribe(callback)
def emit(self, event_type: str, data: Any) -> None:
return self._get_event_bus().emit(event_type, data)
def start_listening(self) -> None:
return self._get_event_bus().start_listening()
def stop_listening(self) -> None:
return self._get_event_bus().stop_listening()
event_bus: EventBus = _LazyEventBus()