how to close and restart PANDA *cleanly* ?

Hello all,
I am try to set a series of tests that use panda.
but I don’t see how to close and restart Panda cleanly.

base.userExit() doesnt’ really works as it raise an exception (nothing happen if the exception is catched).

Any clue ?

maybe:

import sys
sys.exit()

thanks but it doesn’t work,
userExit ends up calling sys.exit and sys.exit exit the interpreter by raising SystemExit(status).

If you don’t want to raise the exception, you can call os._exit(exitstatus) for that.

import os
os._exit(0)

Though, it is not recommended to use this. You better just ignore the SystemExit exception, so try something like this:

import sys
try:
  #put your code here
  sys.exit()
except SystemExit:
  sys.exit()
except:
  print "error:",sys.exc_info()[0]

Why is it not recommended?

I think I wasn’t clear. I don’t want to kill the interpreter, i want to only stop Panda.
I want a mean to launch Panda, do some stuff, stop Panda and then launching Panda again, do some other stuff and stopping Panda. all this automatically.

we use “test driven development” (TDD). So, we build a lot of tests and have some automatic testing mecanism to launch them often.

the “stuff” above are different tests, so the cleanest state of Panda the better. ideally, a complete clean start (which implies a complete clean shutdown).

Have a look at the implementation of the class ShowBase (in ShowBase.py).

The normal way Panda3D handles exit is the following:

  • at startup Panda3D sets sys.exitfunc to ShowBase.exitfunc.
  • to shut down Panda3D the “normal” way the user calls sys.exit( )
  • sys.exit calls sys.exitfunc( ) before destroying the interpreter, which is ShowBase.exitfunc.
  • ShowBase.exitfunc handles shutting down the main window etc.

So you could try to call base.exitfunc( ) yourself. Should close the Panda3D window and free resources.

enn0x

thanks, this will surely help !
I was aware of exitFunc (note the capital F), I see now that there is an exitfunc that roughly do what I want.
I will inquire.