Unsolved PySide2, v5.12.2 - "Internal C++ object already deleted."
-
Good afternoon.
Today, I updated my PySide2 (and shiboken2) from version 5.12.1 to version 5.12.2. My software (a QApplication, running on Windows 10) seems to be working fine since the change. However, upon exiting the GUI, I now see the following error message.
Error in atexit._run_exitfuncs: Traceback (most recent call last): File "C:\Anaconda3\lib\logging\__init__.py", line 2039, in shutdown h.close() RuntimeError: Internal C++ object (MessagePanel) already deleted.
This never happened in version 5.12.1, and there were no code changes made between the two.
For context,
MessagePanel
subclassesQtWidgets.QTextBrowser
andlogging.Handler
, and is added to the main window in the following code block.self.messages = messagepanel.MessagePanel(self) self.messagedock = QtWidgets.QDockWidget('Messages', self, objectName='message dock') self.messagedock.setWidget(self.messages) self.addDockWidget(Qt.RightDockWidgetArea, self.messagedock) logger.addHandler(self.messages)
Any insight into why I've starting seeing this exception would be greatly appreciated.
-
Maybe there was a change in the garbage collection, but as it is a race condition, prehaps it was there before but you did not noticed it. You can simply catch and pass on the error with 'except RuntimeError'.
-
@Alfalfa - it's the only error popping up at all during execution, so I would have been hard pressed to overlook it before. The "except RuntimeError" workaround would certainly silence it, but could have unintended consequences if a different RuntimeError was to occur.
-
Then you might attribute 'h' object to 'self' so it won't be garbage collected by the interpreter
-
@Alfalfa Can you clarify what you mean by 'h' object? As demonstrated in the code block above, the MessagePanel object does connect to "self" (meaning the MainWindow) via the initialization argument. Is there a reason such an issue would arise in version 5.12.2 but not in 5.12.1?
-
My bad, I misread your post and I thought that the error on line 2039 was from your script, and that you tried to call close() on a deleted widget object. I see it is from the logging module so obviously that is not the culprit.
So which line make your program crash? If it is "logger.addHandler(self.messages)", then the same apply; try to attribute it to self to avoid garbage collection.
-
So you're right, it does appear to be a logger issue rather than a Qt one. It wasn't crashing the program at any point, but rather complaining about object cleanup order. Because of the larger structure of our code files, I couldn't assign the logger to wholely be a child of the QMainWindow, but putting the following code in the quit procedure did silence the messages.
import logging logging.raiseExceptions = False
Thanks for your contributions.