sys.exit causing error

In my wxPython app I have the following code (within a class):

        if maintmodes <> 'ADMINISTRATOR':
            msg='User ['+self.currentuser+'] is Not Authorized to use
this function!'
            result=self.showAlert(msg,'ATTENTION')
            sys.exit()

I run the app and the dialog displays. When I click OK I see the
following error in the console:

Debug: e:\Projects\wx2.4\src\msw\app.cpp(446): 'UnregisterClass(no
redraw canvas)' failed with error 0x00000584 (class still has open
windows.).

Heimburger, Ralph P wrote:

In my wxPython app I have the following code (within a class):

        if maintmodes <> 'ADMINISTRATOR':
            msg='User ['+self.currentuser+'] is Not Authorized to use
this function!'
            result=self.showAlert(msg,'ATTENTION')
            sys.exit()

I run the app and the dialog displays. When I click OK I see the
following error in the console:

Debug: e:\Projects\wx2.4\src\msw\app.cpp(446): 'UnregisterClass(no
redraw canvas)' failed with error 0x00000584 (class still has open
windows.).

Because you still have windows that exist and you forced the exit of the app without giving wx a chance to cleanup after itself. Try using wx.GetApp().ExitMainLoop() instead, although the safest is to just call Close(True) on all your top-level windows.

···

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