jdxi_editor.ui.main_thread_gc ============================= .. py:module:: jdxi_editor.ui.main_thread_gc .. autoapi-nested-parse:: Python's garbage collector runs on the main (Qt) thread only. Left automatic, the collector runs in whichever thread happens to allocate when a generation is full: the MIDI request queue's or a recording thread. Collecting a reference cycle that holds Qt objects there destroys them outside the main thread, and Qt crashes (a segmentation fault seen on macOS: "Garbage-collecting" in the request queue's thread). So automatic collection is turned off and the same thresholds are checked from the main thread: by a timer in the app (install), after each test in the tests (collect_if_due). Attributes ---------- .. autoapisummary:: jdxi_editor.ui.main_thread_gc.INTERVAL_MS Classes ------- .. autoapisummary:: jdxi_editor.ui.main_thread_gc.MainThreadGC Functions --------- .. autoapisummary:: jdxi_editor.ui.main_thread_gc.collect_if_due jdxi_editor.ui.main_thread_gc.install Module Contents --------------- .. py:data:: INTERVAL_MS :value: 500 .. py:function:: collect_if_due() -> int Collect the generations whose counts passed their thresholds, as the automatic collector would; returns the objects collected. .. py:class:: MainThreadGC(parent: Optional[PySide6.QtCore.QObject] = None, interval_ms: int = INTERVAL_MS) Bases: :py:obj:`PySide6.QtCore.QObject` .. py:attribute:: timer .. py:function:: install(app: PySide6.QtCore.QObject) -> MainThreadGC Turn automatic collection off and collect from *app*'s thread (call once, after creating the QApplication); the object lives as long as *app*.