[wxPython-users] wx.lib.pubsub and wx.EVT_CLOSE

Josiah Carlson jcarlson at uci.edu
Sun Jun 3 22:01:16 PDT 2007


"Eric Ongerth" <ericongerth at gmail.com> wrote:
> On 6/3/07, Josiah Carlson <jcarlson at uci.edu> wrote:
> >
> > Due to the pubsub using weakrefs, if you are using
> > wx.lib.pubsub.Publisher.subscribe(topic, object.callback_method), then
> > as long as the rest of your program isn't keeping a reference to the
> > widget that you destroyed, pubsub should be dropping its reference to
> > the callback.
> 
> Thanks, Josiah.  I guess the root of the problem, then, is that some parts
> of my program must be keeping references to widgets that have been
> destroyed.  Naively I was counting on Python's reference counting and
> garbage collection to handle that, but now it makes sense to me that Python
> can't be expected to succeed perfectly in that task, given the partial
> disconnect of wxPython wrapping C++ wxWidgets.  Hmm!  Sounds like the
> try/catch approach really is my best bet after all, at least in the
> immediate future.  Thank you for the suggested method.  Can you suggest
> where I might read up on more involved solutions?

I don't know where you could look for more solutions.  At least with the
obj.method-style calls, you can use a variant of what I provided in my
last message.  It should automatically remove method references when
they come to a PyDeadObjectError, and otherwise work the same as it
did before.

As for references that you may be keeping, remember...

class myFrame(wx.Frame):
    def __init__(self, ...):
        ...
        self.panel = wx.Panel(self, ...)
        ...

    def do_something(self, ...):
        ...
        self.panel.Destroy()
        ...

if you run myFrame.do_something(), and you don't later do 'self.panel =
something', then self.panel keeps a reference to the destroyed panel. 
Without seeing your code (where you create references, where you destroy
references, etc.), it would be very difficult for us to help you with
fixing such issues.


 - Josiah





More information about the wxpython-users mailing list