[Phoenix, BUG] Calling InspectorTool twice -> Wrapped C/C++ object deleted

Christian Aichinger <[email protected]>
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
Hi!
When I call wx.lib.inspection.InspectionTool().Show(), close the tool,
and execute the same line again, I get a RuntimeError:
"wrapped C/C++ object of type FillingText has been deleted"

The issue seems to be that wx.py.dispatcher stores weakrefs to its
receivers in a module-level dict. When InspectorTool is first
instantiated, that data is populated. When calling InspectorTool the
second time, dispatcher tries to notify the old callbacks. The Python
objects for those are still around, but the C++ backends were destroyed
when the window was closed. Thus the RuntimeError.

No idea how to fix this, though. Should the Python objects go South when
the window is closed (so the weakrefs invalidate)? Or is dispatcher.py
doing something wrong?

The test script, traceback and a part of my pdb session are attached.

Environment:
Python 3.4.3 (v3.4.3:9b73f1c3e601) [MSC v.1600 32 bit (Intel)] on win32
wxPython 3.0.3.dev1820+49a8884 msw (phoenix)
Windows 7 64 bit (32 bit Python interpreter and Phoenix, though)

Cheers,
Chris

-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
bugreport.txt (text/plain, 2.9 KB)
(venv) C:\path>type test.py
import wx
import wx.lib.inspection

class MyFrame(wx.Frame):
    def __init__(self, parent, id=-1, title=""):
        wx.Frame.__init__(self, parent, id, title)
        self.btn = wx.Button(self, label='click me')
        self.btn.Bind(wx.EVT_BUTTON, self.on_evt_click)
    def on_evt_click(self, evt):
        wx.lib.inspection.InspectionTool().Show()
        self.btn.Label = 'close the inspector and click me again'

if __name__ == '__main__':
    app = wx.App(False)
    frame = MyFrame(None, wx.ID_ANY, "InspectorTool crash")
    frame.Show(True)
    app.MainLoop()

(venv) C:\path>python test.py
Traceback (most recent call last):
File "test.py", line 10, in on_evt_click
  wx.lib.inspection.InspectionTool().Show()
File "C:\path\venv\lib\site-packages\wx\lib\inspection.py", line 104, in Show
  app=self._app)
File "C:\path\venv\lib\site-packages\wx\lib\inspection.py", line 160, in __init__
  style=wx.NO_BORDER,
File "C:\path\venv\lib\site-packages\wx\py\crust.py", line 47, in __init__
  *args, **kwds)
File "C:\path\venv\lib\site-packages\wx\py\shell.py", line 342, in __init__
  self.execStartupScript(startupScript)
File "C:\path\venv\lib\site-packages\wx\py\shell.py", line 421, in execStartupScript
  self.push('')
File "C:\path\venv\lib\site-packages\wx\py\shell.py", line 972, in push
  self.more = self.interp.push(command)
File "C:\path\venv\lib\site-packages\wx\py\interpreter.py", line 82, in push
  command=command, more=more, source=source)
File "C:\path\venv\lib\site-packages\wx\py\dispatcher.py", line 147, in send
  response = _call(receiver, signal=signal, sender=sender, **kwds)
File "C:\path\venv\lib\site-packages\wx\py\dispatcher.py", line 176, in _call
  return receiver(**kwds)
File "C:\path\venv\lib\site-packages\wx\py\filling.py", line 69, in push  # FillingTree.push
  self.display()
File "C:\path\venv\lib\site-packages\wx\py\filling.py", line 159, in display
  if self.IsExpanded(item):
RuntimeError: wrapped C/C++ object of type FillingTree has been deleted

(Pdb) pp dispatcher.connections
{46637776: {'Interpreter.push': [<bound method weakref for <weakref at 0x02E97AE0; to 'FillingTree' at 0x02E9E260>.<weakref at 0x02E97B10; to 'function' at 0x02CBD3D8 (push)>>,
                                 <bound method weakref for <weakref at 0x02E97C60; to 'FillingText' at 0x02E9E300>.<weakref at 0x02E97C90; to 'function' at 0x02CBD7C8 (push)>>,
                                 <bound method weakref for <weakref at 0x02EA72D0; to 'Display' at 0x02E9E3F0>.<weakref at 0x02EA7300; to 'function' at 0x02EB55D0 (push)>>],
            ... } }
(Pdb) bm = dispatcher.connections[46637776]['Interpreter.push'][0]
(Pdb) bm.isDead
0
(Pdb) bm.weakSelf
<weakref at 0x02E97AE0; to 'FillingTree' at 0x02E9E260>
(Pdb) ft = bm.weakSelf()
(Pdb) ft.setText('')
*** RuntimeError: wrapped C/C++ object of type FillingText has been deleted
(Pdb)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.