mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-10-23 16:41:27 +02:00
fix(signal_proxy): make cleanup_signal_proxy idempotent
This commit is contained in:
1 parent
af2c748127
commit
4c4e5febd8
2 files changed
+9
-1
No files matched your search
@@ -22,11 +22,15 @@ def cleanup_signal_proxy(proxy: SignalProxy) -> None:
|
||||
Args:
|
||||
proxy(SignalProxy): The proxy to stop.
|
||||
"""
|
||||
# A repeated SignalProxy.disconnect makes PySide6 warn "Failed to disconnect".
|
||||
if getattr(proxy, "_bec_cleaned_up", False):
|
||||
return
|
||||
# Called explicitly: on subclasses of SignalProxy, PySide6 resolves proxy.disconnect
|
||||
# to the built-in QObject.disconnect instead of SignalProxy.disconnect.
|
||||
SignalProxy.disconnect(proxy)
|
||||
proxy.timer.stop()
|
||||
proxy.args = None
|
||||
proxy._bec_cleaned_up = True
|
||||
|
||||
|
||||
class BECSignalProxy(SignalProxy):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import warnings
|
||||
from unittest import mock
|
||||
|
||||
import pyqtgraph as pg
|
||||
@@ -256,4 +257,7 @@ def test_cleanup_signal_proxy_stops_queued_delivery(qtbot):
|
||||
assert calls == []
|
||||
assert ticks == []
|
||||
assert not proxy.timer.timer.isActive()
|
||||
cleanup_signal_proxy(proxy) # a second call is a no-op
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("always")
|
||||
cleanup_signal_proxy(proxy) # a second call is a no-op, without PySide warnings
|
||||
assert [str(w.message) for w in caught] == []
|
||||
Reference in new issue
Block a user