How to prevent PyQt objects from garbage collecting from different thread? How to prevent PyQt objects from garbage collecting from different thread? multithreading multithreading

How to prevent PyQt objects from garbage collecting from different thread?


This problem popped up on the PyQt mailing list in the thread

"subtle bug in PyQt in combination with Python garbage collector"
http://www.riverbankcomputing.com/pipermail/pyqt/2011-August/030376.html

Kovid Goyal proposed a workaround in
http://www.riverbankcomputing.com/pipermail/pyqt/2011-August/030378.html

where he wrote:

As a workaround in my projects, I disable the automatic garbage collector and run garbage collection manually in the GUI thread via QTimer.

He posted a code example there.


I would recommend using pyqtSignal. You can create signals for your threads to send when their task is completed and the receiver becomes the signal's connected function.