google.appengine.api.runtime.set_shutdown_hook

Registers a function to be called when the server is shutting down.

The shutdown hook will be called when the server shuts down. Your code will have a short amount of time to save state and exit. The shutdown hook should interrupt any long running code you have, e.g. by calling apiproxy_stub_map.apiproxy.CancelApiCalls and/or raising an exception.

hook A no-argument callable which will be called when the server is shutting down.

The previously registered shutdown hook, or None if no hook was registered before.

In some cases it may not be possible to run the shutdown hook before the server exits.