@@ -55,11 +55,7 @@ def _quit_loop_by_timeout(self):
55
55
56
56
def _cleanup (self ):
57
57
if self ._timer is not None :
58
- try :
59
- self ._timer .timeout .disconnect (self ._quit_loop_by_timeout )
60
- except (TypeError , RuntimeError ):
61
- # already disconnected by Qt?
62
- pass
58
+ _silent_disconnect (self ._timer .timeout , self ._quit_loop_by_timeout )
63
59
self ._timer .stop ()
64
60
self ._timer = None
65
61
@@ -131,11 +127,7 @@ def _quit_loop_by_signal(self, *args):
131
127
def _cleanup (self ):
132
128
super (SignalBlocker , self )._cleanup ()
133
129
for signal in self ._signals :
134
- try :
135
- signal .disconnect (self ._quit_loop_by_signal )
136
- except (TypeError , RuntimeError ): # pragma: no cover
137
- # already disconnected by Qt?
138
- pass
130
+ _silent_disconnect (signal , self ._quit_loop_by_signal )
139
131
self ._signals = []
140
132
141
133
@@ -188,11 +180,7 @@ def _signal_emitted(self, signal):
188
180
def _cleanup (self ):
189
181
super (MultiSignalBlocker , self )._cleanup ()
190
182
for signal , slot in self ._slots .items ():
191
- try :
192
- signal .disconnect (slot )
193
- except (TypeError , RuntimeError ): # pragma: no cover
194
- # already disconnected by Qt?
195
- pass
183
+ _silent_disconnect (signal , slot )
196
184
self ._signals .clear ()
197
185
self ._slots .clear ()
198
186
@@ -206,3 +194,12 @@ class SignalTimeoutError(Exception):
206
194
"""
207
195
pass
208
196
197
+
198
+ def _silent_disconnect (signal , slot ):
199
+ """Disconnects a signal from a slot, ignoring errors. Sometimes
200
+ Qt might disconnect a signal automatically for unknown reasons.
201
+ """
202
+ try :
203
+ signal .disconnect (slot )
204
+ except (TypeError , RuntimeError ): # pragma: no cover
205
+ pass
0 commit comments