[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Source code for google.appengine.api.runtime.runtime
#!/usr/bin/env python## Copyright 2007 Google Inc.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#"""Runtime Utilities API... deprecated:: 1.8.1Utilities for interacting with the Python Runtime."""from__future__importwith_statementimportthreadingfromgoogle.appengine.apiimportapiproxy_stub_mapfromgoogle.appengine.api.systemimportsystem_service_pb
[docs]defcpu_usage():"""Returns a SystemStat describing cpu usage, expressed in mcycles. 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 Functions for converting from mcycles to cpu-seconds are located in the quotas API. """return_GetSystemStats().cpu()
[docs]defmemory_usage():"""Returns a SystemStat describing memory usage, expressed in MB. The returned object has the following accessors: - current(): memory currently used by this instance - average1m(): average memory use, over the last minute - average10m(): average memory use, over the last ten minutes """return_GetSystemStats().memory()
def_GetSystemStats():"""Returns stats about the current instance."""request=system_service_pb.GetSystemStatsRequest()response=system_service_pb.GetSystemStatsResponse()apiproxy_stub_map.MakeSyncCall('system','GetSystemStats',request,response)returnresponse__shutdown_mutex=threading.Lock()__shutdown_hook=None__shuting_down=False
[docs]defis_shutting_down():"""Returns true if the server is shutting down."""with__shutdown_mutex:shutting_down=__shuting_downreturnshutting_down
[docs]defset_shutdown_hook(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. Args: hook: A no-argument callable which will be called when the server is shutting down. Returns: 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. """ifhookisnotNoneandnotcallable(hook):raiseTypeError("hook must be callable, got %s"%hook.__class__)global__shutdown_hookwith__shutdown_mutex:old_hook=__shutdown_hook__shutdown_hook=hookreturnold_hook