<div dir="ltr">I am exploring how deleteLater, connections, QObject trees and circular references interact (because of a bug in our pyqt 5.7 app -- I think it might be due to strong references between some qobjects). Just want to bring to people's attention a hard lesson learnt:<span class="inbox-inbox-Apple-converted-space"> </span> if you override disconnectNotify(self, method) from QObject, so that you can check when signals of self get disconnected, beware that self self.receivers() may cause hangs. I have the following code:<div><br></div><div><div><div>def disconnectNotify(self, method):</div><div>    meth_name = bytes(<a href="http://method.name">method.name</a>()).decode()</div><div>    signal = getattr(self, meth_name)</div><div>    num_receivers = self.receivers(signal)  # ***</div></div><div><br></div><div>which gets called because qobjectA.signal is connected to qobjectB.some_slot, and qobjectB gets destroyed (so Qt automatically disconnects signal). Oddly, the problem is the last line (***): when that line is commented out, I can run 10,000 tests without hanging; with it, test will hang about 1% of time.  </div><div><br></div><div>I must say, if there is one thing that I really wish in PyQt, it's ability to interrogate a signal for connections to find the slots (i.e. object methods and functions) connected to it. Of course in a bug-free program, you should never need this because the Observer pattern encourages annonymity of emitters and receivers, but once in a while it would be really nice to be able to check what is connected (because some connections get established only in some circumstances, and sometimes you need to check if a slot is still connected). Being able to do something like this when some_signal is a pyqtSignal(): </div><div><br></div><div>assert self.some_signal.is_connected(some_object.slot)</div><div>assert self.some_signal.num_connections < 5</div><div><br></div><div>would be great. Any chance of extending PyQt to support that?</div><div>Oliver</div></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Oliver<div>My StackOverflow contributions<br><div>My CodeProject articles</div></div><div>My Github projects</div><div>My SourceForget.net projects</div></div></div>