google.appengine.api.runtime module provides utilities for interacting with the Python runtime. You can use it to gather statistics about instance usage, to determine if an instance is shutting down, and to register a shutdown hook.
This package is implemented in the following methods:
- Returns a SystemStat object describing CPU usage, expressed in megacycles (Mcycles). A 600MHz processor gives you 600 Mcycles per second; a 1.2GHz processor gives you 1200 Mcycles per second. The returned object has the following accessors:
total(): total Mcycles consumed by this instance
rate1m(): average Mcycles consumed per second over the last minute
rate10m(): average Mcycles consumed per second over the last ten minutes
You can find functions for converting from Mcycles to CPU seconds in the Quotas API (
- Returns a SystemStat describing memory usage, expressed in megabytes. The returned object has the following accessors:
current(): amount of memory (MB) currently used by this instance
average1m(): average memory usage (MB) over the last minute
average10m(): average memory usage (MB) over the last ten minutes
- Returns true if the instance is shutting down.
Registers a shutdown hook to call when the instance is shutting down. Upon notification of shutdown, your application has a short amount of time to save state and exit. The shutdown hook should interrupt any long-running code you have, for example by calling
apiproxy_stub_map.apiproxy.CancelApiCalls()and/or raising an exception.
- A function with no arguments to call when the instance is shutting down.
Returns the previously registered shutdown hook, or None if no hook was registered.
Warning! In some cases, it may not be possible to run the shutdown hook before the server exits. See Shutdown for more information.