napari: Bug: Segfaults appearing with "QObject::setParent: Cannot set parent, new parent is in a different thread"
🐛 Bug
In the last couple days, I’ve seen this segfault a couple times on main. I’m not quite sure what’s causing it yet, but it tends to happen with mouse movements, perhaps on the canvas, maybe on sliders, not sure… but it crashes napari out to the console
WARNING: QObject::setParent: Cannot set parent, new parent is in a different thread
10:19:54 WARNING QObject::setParent: Cannot set parent, new parent is in a different thread
WARNING: QObject::setParent: Cannot set parent, new parent is in a different thread
10:19:54 WARNING QObject::setParent: Cannot set parent, new parent is in a different thread
WARNING: QObject::setParent: Cannot set parent, new parent is in a different thread
10:19:54 WARNING QObject::setParent: Cannot set parent, new parent is in a different thread
[1] 19897 segmentation fault napari
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (15 by maintainers)
I don’t think exact issue ever made into an official release as it should have been fixed between the release of v0.4.16 and v0.4.17 (first in https://github.com/napari/napari/pull/4983 then in https://github.com/napari/napari/pull/4985).
The goal of https://github.com/napari/napari/pull/5195 was to add some tooling to better detect when this happens, but it’s only available on
main
(i.e. not on v0.4.17). If you’re developing againstmain
, then you can setNAPARI_ENSURE_PLUGIN_MAIN_THREAD=1
to get more info about where this is happening in your code.Generally, napari is not thread safe, so I would only update a layer on the main thread unless some napari documentation says otherwise. If you can directly depend on
superqt
(the full napari viewer does), then you can use theensure_main_thread
decorator to ensure that a particular function/callback executes on the qt main thread.If you still have problems, you might want to create a separate issue with the details.
yeah, that seems like a good plan to me. “update status bar” is a strictly gui related thing, so that should probably have been on the
_qt
side of things all along