def getJson(self, request):
deferred = self.prepareProcessList()
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. It
# will produce HTML and JSON. This class inherits everything from the
# ProcessesResource created above, but substitutes the
# LineReceiverProtocol for a FilteredLineReceiverProtocol
# instead. This resource just illustrates the use of that class.
#
# Note that we also reuse the template file from the parent class. If
# we did not specify it here, the framework would try to use our class
# name to construct a template filename, and no such template exists.
#
评论列表
文章目录