Indeed it does, sys.exit() actually works by raising the exception SystemExit. The low-level C++ interval handler detects this exception and reports it. This is arguably a mistake, but that’s what’s going on.
It’s probably better to call base.userExit() if you want to exit anyway.
def userExit(self):
# The user has requested we exit the program. Deal with this.
if self.exitFunc:
self.exitFunc()
self.notify.info("Exiting ShowBase.")
self.finalizeExit()
def finalizeExit(self):
sys.exit()
Well, that might not be such a great solution, because it doesn’t give Panda a chance to clean itself up gracefully before it exits, which can cause problems on some platforms.
Really, for now, the best solution is not to call this exit function from within an interval, but to use some other mechanism to trigger an exit condition, such as an event. For instance, you can hang a hook on the message “exit” that calls base.userExit(), and then put messenger.send(‘exit’) in your interval.
I’ll put in a special-case handler for SystemExit in the interval manager for the future.
I found that using messenger.send() triggered the same exception. Further investigation revealed that messenger.send() immediately called the corresponding accept handler (hooked to sys.exit), not a delayed until end of frame call or anything.
I used this work-around:
def myexit():
taskMgr.add(sys.exit, "sys.exit")
# and of course, add the interval:
FunctionInterval(myexit),