pb threads at exit

Hello,

When I quit the application, I still have a thread running
accessing a wx.Panel and I get the following exception:

PyDeadObjectError: The C++ part of the object has been
deleted, attribute access no longer allowed. I thought the trick was to use IsBeingDeleted(),
if panel.IsBeingDeleted(): do nothing and return. The thing is that I still get
this exception because even using IsBeingDeleted() accesses the panel since it’s
one of its methods. How can I avoid this exception at exit? Is there a trick to
know within the thread that the application is exiting? Thanks for any help.

M. Vernier

Hello,

When I quit the application, I still have a thread running accessing a
wx.Panel and I get the following exception:

PyDeadObjectError: The C++ part of the object has been deleted,
attribute access no longer allowed. I thought the trick was to use
IsBeingDeleted(), if panel.IsBeingDeleted(): do nothing and return.
The thing is that I still get this exception because even using
IsBeingDeleted() accesses the panel since it's one of its methods. How
can I avoid this exception at exit? Is there a trick to know within
the thread that the application is exiting? Thanks for any help.

M. Vernier

Generally, you should avoid direct access to objects from other
threads, instead sending messages. However, in this case, you can
check for a dead object using

if type(p) == wx._core._wxPyDeadObject:

Which is what I use to detect similiar problems.

···

----- Original Message -----
From: M. Vernier <vernie_m@epita.fr>
Date: Sat, 21 Aug 2004 15:14:26 +0200
Subject: [wxPython-users] pb threads at exit
To: wxpython-users@lists.wxwidgets.org

Chris Mellon wrote:

When I quit the application, I still have a thread running accessing a
wx.Panel and I get the following exception:

PyDeadObjectError: The C++ part of the object has been deleted,
attribute access no longer allowed. I thought the trick was to use
IsBeingDeleted(), if panel.IsBeingDeleted(): do nothing and return.
The thing is that I still get this exception because even using
IsBeingDeleted() accesses the panel since it's one of its methods. How
can I avoid this exception at exit? Is there a trick to know within
the thread that the application is exiting? Thanks for any help.

The problem with this is that the window has already been deleted by the time you try to call IsBeingDeleted so it is too late.

Generally, you should avoid direct access to objects from other
threads, instead sending messages. However, in this case, you can
check for a dead object using

if type(p) == wx._core._wxPyDeadObject:

Which is what I use to detect similiar problems.

The _wxPyDeadObject class has a __nonzero__ method that returns False, so you can just do this to test if a window proxy's C++ object still exists:

  if p:
    # do whatever.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!