def getHtml(self, request):
deferred = self.prepareProcessList()
def cb(processes):
self.logger.debug("getHtml() cb(%r)", processes)
request.write(self.fillTemplate(model = {
"processes": sorted(processes, key=lambda x: int(x.pid))
}))
request.finish()
def eb(failure):
self.logger.debug("getHtml() eb(%r)", failure)
if isinstance(failure.type, Exception):
util.logTwistedFailure(self.logger, failure,
"Exception thrown while getting process list")
self.serverError(request)
request.write("Internal Server Error")
request.finish()
deferred.addCallbacks(cb, eb)
return server.NOT_DONE_YET
#
# This method works the same way as the getHtml() method above,
# but as expected, the callback produces JSON instead of HTML, and
# does not call the template engine.
#
# Note that we use our own JSON encoder. This is actually just an
# extension to the JSON encoder provided by the standard library,
# but it has a few nice features that the standard JSON encoder
# doesn't have. For example, it allows each class to define its
# own JSON encoder method, called __json__(), which will be called
# if available to convert an object to JSON.
#
评论列表
文章目录