Quit / Exit Panda

Is there a way to tell Panda: “Get out of the run method”.
I want that the Game exits in way so that all destrutors are called. if I call sys.exit() its like the C++ exit( x ) from stdlib it just quits the ptrogram without “destroying” the class instances.
Is this possible.

Thanks Martin

sys.exit() is supposed to do the right thing–it cleanly closes all of the Panda windows, and frees all the Panda structures, and so on. I believe Python will also automatically call all of the destructors on outstanding Python objects at that time.

Of course, if you have cyclic references–for instance, object A has a pointer to object B, and object B has a pointer to object A–then Python cannot automatically delete either object A or object B, and these objects are considered “leaked”. They will not be destructed on exit, or at any other time.

David

If written a C++ class and wrapped it to python. In the destructor i made a short debug out put ‘ServerHandle::~ServerHandle’.
My script asks if the ServerHandle was able to connect to the server. If not it calls sys.exit() in this case i can see ‘ServerHandle::~ServerHandle’
but if the users press the ‘ESC’ key and i call sys.exit() i can’t see a ‘ServerHandle::~ServerHandle’
Maybe its because some python classes are storing references to the instance of serverhandle. Are there any sollutions to avoid this uncalled destructor?

Martin

You can ensure that all cycles are cleaned up by designing your Python objects to remove references to other Python objects in some cleanup method, for example obj.cleanup(). Then you ensure that you call obj.cleanup() on all of your objects when you’re ready to exit.

Or you can write your C++ classes so that they have an explicit cleanup() method that will do all of the essential cleanup actions, instead of relying on the destructor to do these; then you can ensure that you call these methods explicitly when you’re ready to exit.

David