Crash-on-exit after call to app.processEvents()
rayosborn at mac.com
Mon May 25 22:35:02 BST 2020
Good to hear from you. I thought for a while that I had managed to fix it with the following code :
app = NXConsoleApp()
for w in QApplication.topLevelWindows():
del app.window, app.app
It proved to be a false dawn - the problem started to recur again. I’ll see if your version catches things that mine missed, and let you know.
I have spent a lot of time trying to cover up PyQt5 bugs in the past year. The problem is that I can’t guarantee that my users will have the latest version of PyQt, so even if it is fixed in v5.14, I still have to patch the code. I just have no idea why simply calling processEvents() triggers the bug. If I knew that, perhaps it would give some clue how to work around it.
> On May 25, 2020, at 3:38 PM, V. Armando Sole <sole at esrf.fr> wrote:
> 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:
> # we cannot afford to crash here
> if id(widget) != id(self):
> if widget.parent() is None:
> _logger.debug("Error closing widget")
> return qt.QMainWindow.closeEvent(self, event)
> Best regards,
> 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 <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 <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()
>> # 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt