The Backend API is deprecated as of March 13, 2014. Although Google will
continue to support the Backend API in accordance with our
terms of service
, it is strongly recommended that all new applications
use the
Modules API
instead.
The
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:
- cpu_usage ()
-
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 (
google.api.quota
). -
- memory_usage ()
-
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
-
- is_shutting_down ()
- Returns true if the backend is shutting down.
- set_shutdown_hook (hook)
-
Registers a shutdown hook to call when the backend 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.Arguments
- hook
- A function with no arguments to call when the backend 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 Stopping Backends for more information.