Skip to content

#186 Fix the crash induced by destruction of signal object in pool thread

Marko Vendelin requested to merge bug/186-crash-bg-recalc into main

With QRunnable being destroyed automatically, we had Job signals destroyed automatically as well from the pool thread. As a result, I could observe crashes as described in #186 (closed).

To avoid the crashes, Signals instances are kept in the separate class _instances attribute. When job is finished, it emits _finished signal which is caught by the Signals object itself. As Signals object is in the main thread and receives the signal in queued manner, it will be able to remove last reference to itself from the main thread. Then Python garbage collector will kick in and destroy object as needed.

I tried to avoid using QRunnable's automatic deletion, but that kept some references active in QThreadPool that I didn't figure out how to remove. As a result, all jobs were kept in memory and never deleted (debugged using __del__ method).

Please review

Fixes #186 (closed)

Merge request reports