INNER CODE UNIT · Python

enableEventLoopGarbageCollection

toolsforexperiments/plottr · plottr/__init__.py:71

def enableEventLoopGarbageCollection(app: QtCore.QCoreApplication,
                                     interval_sec: float = 1.0) -> None:
    """Run Python's cyclic garbage collector only from the Qt event loop.

    Flowcharts, nodes and their pyqtgraph/Qt objects form reference cycles,
    so once discarded (e.g., a closed plot window) they are only freed by
    Python's cyclic garbage collector. By default that collector runs
    whenever an allocation happens to cross its threshold -- including
    while Qt is in the middle of constructing other graphics items, or in a
    worker thread. Destroying Qt objects at such points can segfault the
    process.

    This disables automatic collection and instead collects periodically
    from a timer in the GUI thread's event loop (via pyqtgraph's
    ``GarbageCollector``, see
    https://github.com/pyqtgraph/pyqtgraph/blob/pyqtgraph-0.14.0/pyqtgraph/util/garbage_collector.py),
    plus once more when the application is about to quit, so that no Qt
    objects are left for interpreter shutdown.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…