Crash-on-exit after call to app.processEvents()
V. Armando Sole
sole at esrf.fr
Mon May 25 21:38:05 BST 2020
Hi Ray,
I do not know if it will help your case. I was getting rid of some
crashes on exit by deleting all widgets that had no parent. For
instance, when closing the QMainWindow by doing:
def closeEvent(self, event):
if __name__ == "__main__":
app = qt.QApplication.instance()
allWidgets = app.allWidgets()
for widget in allWidgets:
try:
# we cannot afford to crash here
if id(widget) != id(self):
if widget.parent() is None:
widget.close()
except:
_logger.debug("Error closing widget")
return qt.QMainWindow.closeEvent(self, event)
Best regards,
Armando
On 25.05.2020 19:48, Raymond Osborn wrote:
> I added a call to QtWidgets.QApplication.instance().processEvents() in order to force adjustResize() to work when switching tabs (that's another story). It succeeded in fixing my resize issue, but now it triggers a segfault when I exit the application. This seemed to be related to the bug described in https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#crashes-on-exit. One fix, suggested by @ekhumoro on stackoverflow (https://stackoverflow.com/questions/59120337/why-does-pyqt-sometimes-crash-on-exit) was to delete the main window and the app first, but that doesn't seem to fix it. I am running PyQt 5.12 because that is the last version supported by conda, so I can't test the one-exit fix in v5.13, and my users probably wouldn't have it installed anyway. It happens on Macs and linux.
>
> What I am asking is if there are additional things to try in addition to @ekhumoro's suggestion? Basically he suggests doing something like:
>
> def main():
> app = QApplication(sys.argv)
> main_window = MainWindow()
> main_window.show()
> app.exec_()
> # ensure correct deletion order
> del main_window, app
>
> Does anyone understand why the crash only occurs if I have calls to processEvents() in the code? It never happens when I remove them.
>
> Thanks,
> Ray
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200525/39c84e78/attachment-0001.htm>
More information about the PyQt
mailing list