Quit the program

Hello,

I have a server application. I use

loadPrcFileData("", "window-type none")
[code]
 to
[/code]
to have no rendering of my world.

I wish to know, if you know how to stop (without Ctrl C) my server, and how to intercept the closing of the app, because on stopping I wish to save the state of the world.

Thanks a lot...

How you stop the server is up to you. You’ll have to write code that listens for some event, like a command from the client maybe, or from some control program that you write, and calls sys.exit() in response.

Or, you can continue to use ^C to stop the server. ^C actually works by generating a KeyboardInterrupt exception, at least I think it works that way on all platforms (not 100% sure about Windows), so you should be able to put a try… except KeyboardInterrupt around your whole program to detect when ^C is hit and do the appropriate thing.

David

you could try the at-exit module:

docs.python.org/library/atexit.html

Atexit works pretty fine.

Thank you