-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Don't bother disconnecting signals in TimerQt.__del__. #8450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't bother disconnecting signals in TimerQt.__del__. #8450
Conversation
The current implementation sometimes raises an error at exit. For example, run `examples/animations/animate_decay.py` (under the Qt5Agg backend) and wait after the x-axis has been updated at least once; then close the window. *Occasionally*, the following error will be printed at exit: ``` Exception ignored in: <bound method TimerQT.__del__ of <matplotlib.backends.backend_qt5.TimerQT object at 0x7f74a65f5668>> Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 202, in __del__ self._timer.timeout.disconnect(self._on_timer) TypeError: 'method' object is not connected ``` As far as I can tell there is no real rationale for bothering to explicitly disconnect the callback -- the C++-level QTimer object is about to be garbage-collected anyways.
Does this prevent a circular set of references? Nominally 👍 but want to think a bit more. |
The C++-level QTimer object keeps a reference to self._on_timer whereas the Python-level TimerQt object keeps a reference to the QTimer, so there is already a circular ref in the way the class is designed. If we manage to reach a point where |
Hurray for GC race-conditions! I am leaning a bit towards simply swallowing the TypeError exception. What if we redesign the class to no longer have the cyclic reference? Then we would need the |
note, I am not suggesting that we redesign the class, just simply saying that if in the future the class gets redesigned, one may forget to add back the |
I don't understand the insistence on keeping del. |
There's no need to disconnect here, I think I was just being way overly cautious. Qt disconnects in destructors at the C++ level. |
Going to backport this |
…merqt-__del__ MNT: Don't bother disconnecting signals in TimerQt.__del__.
backported to v2.0.x as b160593 |
The current implementation sometimes raises an error at exit. For
example, run
examples/animations/animate_decay.py
(under theQt5Agg backend) and wait after the x-axis has been updated at least
once; then close the window. Occasionally, the following error will
be printed at exit:
As far as I can tell there is no real rationale for bothering to
explicitly disconnect the callback -- the C++-level QTimer object is
about to be garbage-collected anyways.