diff --git a/griptape/events/event_bus.py b/griptape/events/event_bus.py index b7954480e1..f6d797473c 100644 --- a/griptape/events/event_bus.py +++ b/griptape/events/event_bus.py @@ -24,8 +24,9 @@ def add_event_listeners(self, event_listeners: list[EventListener]) -> list[Even return [self.add_event_listener(event_listener) for event_listener in event_listeners] def remove_event_listeners(self, event_listeners: list[EventListener]) -> None: - for event_listener in event_listeners: - self.remove_event_listener(event_listener) + with self._thread_lock: + for event_listener in event_listeners: + self.remove_event_listener(event_listener) def add_event_listener(self, event_listener: EventListener) -> EventListener: with self._thread_lock: diff --git a/tests/unit/events/test_event_listener.py b/tests/unit/events/test_event_listener.py index f35bc5416f..6af1213b16 100644 --- a/tests/unit/events/test_event_listener.py +++ b/tests/unit/events/test_event_listener.py @@ -94,8 +94,8 @@ def test_add_remove_event_listener(self, pipeline): mock1 = Mock() mock2 = Mock() # duplicate event listeners will only get added once - event_listener_1 = EventBus.add_event_listener(EventListener(mock1, event_types=[StartPromptEvent])) - EventBus.add_event_listener(EventListener(mock1, event_types=[StartPromptEvent])) + event_listener_1 = EventBus.add_event_listener(EventListener(mock1, id="1", event_types=[StartPromptEvent])) + EventBus.add_event_listener(EventListener(mock1, id="1", event_types=[StartPromptEvent])) event_listener_3 = EventBus.add_event_listener(EventListener(mock1, event_types=[FinishPromptEvent])) event_listener_4 = EventBus.add_event_listener(EventListener(mock2, event_types=[StartPromptEvent]))