def getJson(self, request):
deferred = self.getProcessList()
def cb(processes):
self.logger.debug("getJson() cb(%r)", processes)
request.write(json.dumps({"processes": processes}))
request.finish()
def eb(failure):
self.logger.debug("getJson() eb(%r)", failure)
if isinstance(failure.type, Exception):
util.logTwistedFailure(self.logger, failure,
"Exception thrown while getting process list")
self.serverError(request)
request.write(json.dumps({"error": "500 Internal Server Error"}))
request.finish()
deferred.addCallbacks(cb, eb)
return server.NOT_DONE_YET
#
# Create a resource class for processes owned by the user root. Since
# this class is now a child of ProcessesResource, we can call the
# getProcessList() method of that class by using getParent().
#
# The data returned is processed in the callback by filtering the
# process list on the ProcessModel 'user' attribute, so that the
# filtered list only contains processes owned by root. The filtered
# list is then passed to the template system just like in example 4.
#
评论列表
文章目录