Random segfaults when resizing figures

35 views
Skip to first unread message

James Campbell

unread,
Jul 7, 2022, 11:16:02 AM7/7/22
to pyqtgraph
I'm using pyqtgraph in a PyQt5 app.  I have a tabbed window (outside the main window) where each tab has a figure.  Sometimes, when resizing a the window displaying a figure, I'll randomly get a segfault crash.  This happens infrequently, and usually I dont run uinto this error.

The annoying thing is that these segfaults are not reproducible as far as I can tell.  

Does anyone have any good advice on how one goes about debugging such issues?  Are there well known issues that may cause such sporadic crashes?

I was considering updating my app to PyQt6 to see if that will help things.  Is PyQt6 more stable in this regard?

Thanks


Ognyan Moore

unread,
Jul 7, 2022, 12:31:59 PM7/7/22
to pyqt...@googlegroups.com
Hi James,

Troubleshooting an intermittent segfault can be summarized as an exercise in frustration, causes can be all over the place, but it can be really tough.  One thing you can do is enable the python faulthandler.  This may help with identifying where in the code things are blowing up (but that's not necessarily a guarantee that that is where the issue is).

If you are unable to reproduce the issue with any reliability (which I maintain doing this is a critical step and effort should be made to attempt to do this), and migrating to a different binding is feasible, I would recommend doing that.  That's no guarantee to fix the issue though.

Some other frequent causes of segfaults can involve the python garbage collection cleaning up an object that may have some kind of internal Qt reference.  These can sometimes occur when using the `del` operator or calling `gc.collect()`.

Here is a link to closed PRs with the word "segfault" in there. Not all these PRs addressed a segfault, but you can see what changes were made to fix some segfaults.

Hope that helps,
Ogi

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/9b54d993-934a-4719-aa61-d9869a4c3a03n%40googlegroups.com.

Patrick

unread,
Jul 11, 2022, 8:44:02 PM7/11/22
to pyqtgraph
Hi James,

Just a further suggestion to those above about things that trigger segfaults. Ensure you don't access (and particularly modify) any Qt objects such as UI elements etc from outside the main Qt event loop thread. That is, if you have some native python threading.Thread doing data updates or something in the background, don't attempt to change UI element values or do a pyqtgraph plot.setData() call from inside the thread. Instead, set up an appropriate "update_needed" QSignal and emit that from inside the python thread, and from your Qt UI thread use update_needed.connect(handler_function) to let the work happen from inside the Qt event loop.

Patrick
Reply all
Reply to author
Forward
0 new messages