fix(bec-dispatcher): add disconnect_owner method to manage widget slot disconnections

This commit is contained in:
2026-05-20 17:30:17 +02:00
parent c4d4b78846
commit 269228e79e
2 changed files with 19 additions and 0 deletions
+18
View File
@@ -22,6 +22,7 @@ logger = bec_logger.logger
if TYPE_CHECKING: # pragma: no cover
from bec_lib.endpoints import EndpointInfo
from bec_widgets.utils.bec_widget import BECWidget
from bec_widgets.utils.rpc_server import RPCServer
@@ -42,6 +43,7 @@ class QtThreadSafeCallback(QObject):
self.cb_info = cb_info
self.cb = cb
self.cb_owner = louie.saferef.safe_ref(cb.__self__) if hasattr(cb, "__self__") else None
self.cb_ref = louie.saferef.safe_ref(cb)
self.cb_signal.connect(self.cb)
self.topics = set()
@@ -240,6 +242,22 @@ class BECDispatcher:
# pylint: disable=protected-access
self.disconnect_topics(self.client.connector._topics_cb)
def disconnect_owner(self, owner: BECWidget):
"""
Disconnect all slots owned by a particular widget.
Args:
owner(BECWidget): The owner widget whose slots should be disconnected
"""
slots_to_disconnect = []
for connected_slot in self._registered_slots.values():
if connected_slot.cb_owner is not None and connected_slot.cb_owner() == owner:
slots_to_disconnect.append(connected_slot)
for slot in slots_to_disconnect:
topics = slot.topics.copy()
for topic in topics:
self.disconnect_slot(slot.cb, topic)
def start_cli_server(self, gui_id: str | None = None):
"""
Start the CLI server.
+1
View File
@@ -362,6 +362,7 @@ class BECWidget(BECConnector):
"""Wrap the close even to ensure the rpc_register is cleaned up."""
try:
if not self._destroyed:
self.bec_dispatcher.disconnect_owner(self)
self.cleanup()
self._destroyed = True
finally: