Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我应该写一些像这样的代码:
class SomePage(Resource): def render_GET(self, request): d = DoSomeQuery() # if d run success # return "success" # if d fails # return "fail"
我的意思是 render_GET 函数的返回值取决于延迟结果。
我怎样才能做到这一点?
添加这个:
d.addCallbacks(lambda _: "success", lambda _: "fail") d.addCallback(request.write) d.addBoth(lambda _: request.finish()) return server.NOT_DONE_YET