Exception Thrown on Window Close

It does not seem normal that I should get an error after I close the window.

Error after window closes:

I just have a simple code.

from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
    def __init__(self):
base = MyApp()

Is the code okay? What would cause the error?

File “E:\GameDevelopment\PythonTest\PythonTest\PythonTest.py”, line 32, in (Current frame)

Can you get the specific error from that? (It might help to know what, specifically, the system is upset about.)

Offhand, the code looks okay to me.

This is a bug of your IDE. Try running your example through the command line to make sure of this.

Wow. That was quick. Just as I hit the post button, I realized I forgot to put the error. Thanks.

1 Like

Okay. So do you have any idea how I can fix this? I am using Visual Studio 2019.

I think this is just a SystemExit exception being thrown by sys.exit(). If your IDE is reporting this, this is a bug in your IDE.

You can work around this by overriding finalizeExit() in your ShowBase subclass to do nothing, eg.:

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):
    def __init__(self):

    def finalizeExit(self):

base = MyApp()

However, the application will stay running after closing the window. Calling self.taskMgr.stop() inside finalizeExit may be enough to address that.

Thanks. that got rid of the error, but I have to manually close the console window. Not something I want to keep doing. Laziness maybe. :smile:

I googled sys.exit exception, and it seems it’s a thing with python (python sys.exit causes exception). Which is good, because VS usually don’t have bugs. If any they get fixed pronto.

I am looking into how best to go about getting a clean exit. Currently, I am looking at this.
I’ll see how it goes. Thanks.

sys.exit() does throw an exception, because that’s how it works—a SystemExit exception, which is supposed to be handled by the runtime normally. If the IDE is complaining about this, that is certainly a bug (or at least a very peculiar behaviour) of the IDE.

Okay. I am using this:

def finalizeExit(self):

Since it prompts for a key press. Whereas pass doesn’t.
I also see that I have no choice but to manually close the console, as long as I am debugging the application. So lazy don’t cut it. Oh man. :frowning_face::smile:

Thanks for the helpful tips. …and thanks for the responses, guys.
I plan on trying out SPE and Sublime later. I’ll let you know how that goes.

Just wondering. Since

sys.exit() does throw an exception, because that’s how it works

, would the IDE that recognizes this, and reports it, have a bug. Or would that not be how the IDE is supposed to work?

Did you see my message about using self.taskMgr.stop() instead of sys.exit(0)? Does that not cause the console to be automatically closed?

Ah. No I did not see that actually, but I just tried it. It doesn’t do anything.

I’m good to go though.
I’ve been reading up on python, and exiting.
Learning a lot… I hope. :frowning: :smile:

    def finalizeExit(self):
        except SystemExit:
            print("Program terminated with SystemExit exception")
        # The finally clause is part of the crashing-application 
        # strategy. You use this clause to perform any required 
        # last-minute tasks. Normally, the finally clause is quite 
        # short and uses only calls that are likely to succeed 
        # without further problem.

That’s the code I decided to go with.