Errors when app is closed by logging out

I have an embedded wxPython application on Windows XP. If the application
is running and the user tries to log out, I get a varying number of error
dialogs something like:

  Exceptions typeError: NoneType does not have function in ignored

or variants of that. I've found a few things that caused it and they seem
related to the order in which the Python modules are unloaded or finalized.
For instance, I had a module with the following statement at global scope:

_hiliteColor = wxColor(120, 220, 120);

It seemed to me that what was happening was that the wxPython module
was being unloaded before the final reference count to the object went
down to 0.

Although I've fixed the things I could find, I'm still getting several of
these stupid dialogs. So, my questions:

1) Is there any way to control the order of shutdown events in Python
or wxPython?

2) Failing that, how can I catch all of the different variants of shutdown or
close events from Windows and have them work in the same way?

3) Failing that, can someone just shoot me in the head?

···

-------------------------------------------------------------------------------------
Jeff Kotula Systems Architecture Manager
Vital Images jkotula@vitalimages.com

Although the module is mathematically correct, the solution
is physically impossible. Either that, or you have actually
created mass and I will apologize for underestimating
your power.
    -- Things to Tell Programmers,
        Dilbert Short List

Jeff Kotula wrote:

It seemed to me that what was happening was that the wxPython module
was being unloaded before the final reference count to the object went
down to 0.

Yes, basically.

Although I've fixed the things I could find, I'm still getting several of
these stupid dialogs. So, my questions:

1) Is there any way to control the order of shutdown events in Python
or wxPython?

If you mean Python object cleanup, then no.

2) Failing that, how can I catch all of the different variants of shutdown or
close events from Windows and have them work in the same way?

The app normally exits when MainLoop() returns. MainLoop returns when all the top level windows (frames and dialogs) have been closed and destroyed. The Destroy method for the top level windows doesn't destroy it immediatly, but when the next idel event happens. When a frame is closed, either as a result of calling frame.Close() or by the user clicking on the close button in the title bar, then there is an EVT_CLOSE event that you can catch and potentially prevent the closing of the frame. The default handler just calls frame.Destroy().

Does this help?

You can also short-circuit the normal shutdown by calling app.ExitMainLoop() but I think it's better to allow normal shutdown to happen.

3) Failing that, can someone just shoot me in the head?

Okay, but wouldn't it just be easier to not use global wx objects? :wink: If that doesn't work then you can change the __del__ method of the objects involved as suggested two weeks ago today by Mike Fletcher to look like this:

    def __del__(self,gdic=gdic):
         if self.thisown == 1 :
             d = gdic.delete_wxImageList
             if d:
                 d(self)

···

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