Help debugging a 'RuntimeError: wrapped C/C++ object of type JLCPCBTools has been deleted' error

I work on a wxPython plugin for Kicad, the circuit board designer.

Recently I made a change, to use wx.QueueEvent() to send log text to the main thread for processing as calling TextCtrl::WriteText() was resulting in hangs or missing text.

After this change users have been reporting these RuntimeErrors, Exception on python action plugin code · Issue #475 · Bouni/kicad-jlcpcb-tools · GitHub

Any pointers to what the issue is would be helpful. I’m stumped and we could revert the change but then we’d be back calling UI functions from outside of the UI thread (which I understand isn’t a good thing).

Is that a deep clone of the event / data you’re passing?
https://docs.wxwidgets.org/3.0/classwx_evt_handler.html#acffd03bf407a856166ea71ef0318b59a

I’m not sure…

The argument coming in is a LogRecord, but we are generating a local like:

msg = self.format(record)

Which looks like its calling logging.Handler.format

and then we build a local to pass it to the queue and format it with an f-string

    def emit(self, record):
        """Marshal the event over to the main thread."""
        msg = self.format(record)
        wx.QueueEvent(self.event_destination, LogboxAppendEvent(
                msg=f"{msg}\n"
            )
        )

so I don’t think we are doing a deep copy but rather a bit of a clone of the data being passed. Unless I’m missing something, which I clearly am.