Skip to content

Fix qt gc segfault - #474

Merged
jenshnielsen merged 2 commits into
toolsforexperiments:masterfrom
jenshnielsen:fix-qt-gc-segfault
Oct 6, 2026
Merged

jenshnielsen merged 2 commits into
toolsforexperiments:masterfrom
jenshnielsen:fix-qt-gc-segfault

Conversation

@jenshnielsen

@jenshnielsen jenshnielsen commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Use garbage collector from pyqtgraph in qt apps. This should resolve crashes due to the std garbage collector not working well with the qt event loop

@jenshnielsen
jenshnielsen marked this pull request as ready for review October 6, 2026 06:54
@jenshnielsen
jenshnielsen enabled auto-merge October 6, 2026 08:09
Flowcharts, nodes and their pyqtgraph/Qt objects form reference cycles, so
discarded ones are only freed by Python's cyclic garbage collector. When an
allocation-triggered collection fires while Qt is constructing graphics
items for another flowchart, destroying the old Qt object trees can
segfault the process. This crashed the test suite (mid-run on Windows, at
interpreter shutdown on Linux CI with Python 3.14) and can also hit the apps,
e.g. when inspectr replaces a plot window's flowchart.

- Add plottr.enableEventLoopGarbageCollection(), which uses pyqtgraph's
  GarbageCollector to collect only from the Qt event loop, plus once on
  aboutToQuit, and enable it in the standalone apps (autoplot, inspectr,
  monitr, apprunner). Library use is unchanged since this affects the whole
  interpreter; the README documents how to opt in.
- In the test suite, disable automatic collection during each test and
  collect explicitly afterwards.
dataLoaded is emitted before the queued onThreadComplete() slot updates
the flowchart output, so wait for the new data as the first half of the
test already does.
@jenshnielsen
jenshnielsen merged commit fd09f89 into toolsforexperiments:master Oct 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants