Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PySide2, v5.12.2 - "Internal C++ object already deleted."
Forum Updated to NodeBB v4.3 + New Features

PySide2, v5.12.2 - "Internal C++ object already deleted."

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 2 Posters 8.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JC89
    wrote on last edited by
    #1

    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 subclasses QtWidgets.QTextBrowser and logging.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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alfalfa
      wrote on last edited by
      #2

      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'.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JC89
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Alfalfa
          wrote on last edited by
          #4

          Then you might attribute 'h' object to 'self' so it won't be garbage collected by the interpreter

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JC89
            wrote on last edited by
            #5

            @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?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alfalfa
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JC89
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved