Skip to content

Commit 5a0eb89

Browse files
committed
lazy load eventbus
1 parent fac0152 commit 5a0eb89

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Global event bus instance - uses SqliteEventBus for cross-process functionality
22
from eval_protocol.event_bus.event_bus import EventBus
3-
from eval_protocol.event_bus.sqlite_event_bus import SqliteEventBus
43

5-
event_bus: EventBus = SqliteEventBus()
4+
5+
def _get_default_event_bus():
6+
from eval_protocol.event_bus.sqlite_event_bus import SqliteEventBus
7+
8+
return SqliteEventBus()
9+
10+
11+
# Lazy property that creates the event bus only when accessed
12+
class _LazyEventBus(EventBus):
13+
def __init__(self):
14+
self._event_bus: EventBus | None = None
15+
16+
def _get_event_bus(self):
17+
if self._event_bus is None:
18+
self._event_bus = _get_default_event_bus()
19+
return self._event_bus
20+
21+
def __getattr__(self, name):
22+
return getattr(self._get_event_bus(), name)
23+
24+
25+
event_bus: EventBus = _LazyEventBus()

0 commit comments

Comments
 (0)