1 回答

阿波羅的戰車
TA貢獻1862條經驗 獲得超6個贊
同時在get或者post方法處理上應用@tornado.web.asynchronous和@tornado.gen.engine裝飾器,可以非常方便的和有callback參數的異步方法配合實現非阻塞請求處理。
這里不想說官方的那個例子,因為官方的例子給的本來就是用異步的http客戶端來拉取數據然后自己轉到回調函數執行,討論http客戶端的代碼不在本文范圍內。于是我用一個簡單的函數來演示,且這樣更能說明問題。
class RegisterHandler(basehandler.BaseHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self, *arg, **args):
response = yield tornado.gen.Task(self.method_while)
print "response",response
self.finish()
這里不想說官方的那個例子,因為官方的例子給的本來就是用異步的http客戶端來拉取數據然后自己轉到回調函數執行,討論http客戶端的代碼不在本文范圍內。于是我用一個簡單的函數來演示,且這樣更能說明問題。
class RegisterHandler(basehandler.BaseHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self, *arg, **args):
response = yield tornado.gen.Task(self.method_while)
print "response",response
self.finish()
- 1 回答
- 0 關注
- 986 瀏覽
添加回答
舉報
0/150
提交
取消