labscript-suite / runmanager

𝗿𝘂𝗻𝗺𝗮𝗻𝗮𝗴𝗲𝗿 is an intuitive graphical interface for controlling 𝘭𝘢𝘣𝘴𝘤𝘳𝘪𝘱𝘵 𝘴𝘶𝘪𝘵𝘦 experiments. Includes multi-dimensional parameter scans and a remote programming interface for automation.
http://labscriptsuite.org
Other
3 stars 45 forks source link

segfault during exit #74

Closed chrisjbillington closed 4 years ago

chrisjbillington commented 4 years ago

I'm getting a segfault at exit on Linux.

I tracked it down to an atexit function added by PyQt, and on a hunch guessed that it might be due to us having two QApplication objects in the interpreter - one for the splash screen and one for runmanager itself. Recently when testing under PySide2 I discovered this is not allowed in PySide2, and I'm pretty sure it shouldn't be allowed anywhere.

Turns out using the QApplication that already exists makes the segfault go away. So we should do this in runmanager and the other GUI apps:

qapplication = QtWidgets.QApplication.instance()
if qapplication is None:
    qapplication = QtWidgets.QApplication(sys.argv)

to use the process-wide QApplication singleton if it already exists. The splash screen code is already doing this, so the resulting QApplication will have had sys.argv passed to it regardless of who initialised it.

I wonder if this could be responsible for segfaults at startup we sometimes hear about

philipstarkey commented 4 years ago

Yes we should absolutely only be creating one QApplication object. Pretty sure I've answered similar questions on stack overflow before (about random segfaults).

The Qt docs also state this:

Only one application object should be created.

chrisjbillington commented 4 years ago

Great. I'll fix this in each app to fix the bug and as a step toward PySide2 compatibility.