PyDeadObjectError Not Defined

I just read a day or so ago (?) in thread about using a try-except
to attempt to close a window that may already be closed. This seems
perfectly reasonable to me. However, when this is actually used I
get:

    NameError:  Global name 'pydeadobjecterror' is not defined

The code and screenshots are attached. I'm using a custom exception

traceback printout because the built-in Python one is a visual
nightmare.

If you run this code be sure to click the button in the popup window

within 5 seconds of its appearance. There is a 50% random chance on
each run that either just a simple Close() is used as opposed to the
try-.Close()-except-PyDeadObjectError technique.

If the "except PyDeadObjectError:  pass" clause is changed to a

generic “except: pass” then it does work properly. This tells me
the PyDeadObjectError exception is not working properly.

I guess this makes this thread more of a "heads up" message rather

than a “how do I fix this” question.

Has this specifically been fixed in later WX version releases ?

Thanks in advance,

Ray

PyDeadObjectError_TEST.PY (5.15 KB)

CustomMessagePopup.PY (2.18 KB)

PY_DEAD_OBJECT_ERROR_RAISED.PNG

PY_DEAD_OBJECT_ERROR_NOT_DEFINED.PNG

SiteCustomize.PY (1.78 KB)

Hi,

I just read a day or so ago (?) in thread about using a try-except to
attempt to close a window that may already be closed. This seems perfectly
reasonable to me. However, when this is actually used I get:

NameError:  Global name 'pydeadobjecterror' is not defined

The code and screenshots are attached. I'm using a custom exception
traceback printout because the built-in Python one is a visual nightmare.

If you run this code be sure to click the button in the popup window within
5 seconds of its appearance. There is a 50% random chance on each run that
either just a simple Close() is used as opposed to the
try-.Close()-except-PyDeadObjectError technique.

If the "except PyDeadObjectError: pass" clause is changed to a generic
"except: pass" then it does work properly. This tells me the
PyDeadObjectError exception is not working properly.

Because the PyDeadObjectError is a wxPython exception and is not in
the global Python namespace, you need to reference it from wx.

i.e)

try:
   foo()
except wx.PyDeadObjectError:
   pass

I guess this makes this thread more of a "heads up" message rather than a
"how do I fix this" question.
Has this specifically been fixed in later WX version releases ?

There is nothing to fix in wx, the error is in your code.

Cody

···

On Wed, Aug 25, 2010 at 2:45 PM, Ray Pasco <pascor@verizon.net> wrote:

Try wx.PyDeadObjectError.

Cheers, Frank

···

2010/8/25 Ray Pasco <pascor@verizon.net>:

I just read a day or so ago (?) in thread about using a try-except to
attempt to close a window that may already be closed. This seems perfectly
reasonable to me. However, when this is actually used I get:

NameError:  Global name &#39;pydeadobjecterror&#39; is not defined

Egads ! I think I needed some sleep at the time.

Thanks

Ray

···

On Aug 25, 3:54 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

On Wed, Aug 25, 2010 at 2:45 PM, Ray Pasco <pas...@verizon.net> wrote:
> I just read a day or so ago (?) in thread about using a try-except to
> attempt to close a window that may already be closed. This seems perfectly
> reasonable to me. However, when this is actually used I get:

> NameError: Global name 'pydeadobjecterror' is not defined

> The code and screenshots are attached. I'm using a custom exception
> traceback printout because the built-in Python one is a visual nightmare.

> If you run this code be sure to click the button in the popup window within
> 5 seconds of its appearance. There is a 50% random chance on each run that
> either just a simple Close() is used as opposed to the
> try-.Close()-except-PyDeadObjectError technique.

> If the "except PyDeadObjectError: pass" clause is changed to a generic
> "except: pass" then it does work properly. This tells me the
> PyDeadObjectError exception is not working properly.

Because the PyDeadObjectError is a wxPython exception and is not in
the global Python namespace, you need to reference it from wx.

i.e)

try:
foo()
except wx.PyDeadObjectError:
pass

> I guess this makes this thread more of a "heads up" message rather than a
> "how do I fix this" question.
> Has this specifically been fixed in later WX version releases ?

There is nothing to fix in wx, the error is in your code.

Cody