<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 非阻塞式異步請求 當一個處理請求的行為被執行之后,這個請求會自動地結束。因為 Tornado 當中使用了 一種非阻塞式的 I/O 模型,所以你可以改變這種默認的處理行為——讓一個請求一直保持 連接狀態,而不是馬上返回,直到一個主處理行為返回。要實現這種處理方式,只需要 使用 `tornado.web.asynchronous` 裝飾器就可以了。 使用了這個裝飾器之后,你必須調用 `self.finish()` 已完成 HTTTP 請求,否則 用戶的瀏覽器會一直處于等待服務器響應的狀態: ``` class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): self.write("Hello, world") self.finish() ``` 下面是一個使用 Tornado 內置的異步請求 HTTP 客戶端去調用 FriendFeed 的 API 的例 子: ``` class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): http = tornado.httpclient.AsyncHTTPClient() http.fetch("http://friendfeed-api.com/v2/feed/bret", callback=self.on_response) def on_response(self, response): if response.error: raise tornado.web.HTTPError(500) json = tornado.escape.json_decode(response.body) self.write("Fetched " + str(len(json["entries"])) + " entries " "from the FriendFeed API") self.finish() ``` 例子中,當 `get()` 方法返回時,請求處理還沒有完成。在 HTTP 客戶端執行它的回 調函數 `on_response()` 時,從瀏覽器過來的請求仍然是存在的,只有在顯式調用了 `self.finish()` 之后,才會把響應返回到瀏覽器。 關于更多異步請求的高級例子,可以參閱 demo 中的 `chat` 這個例子。它是一個使用 [long polling](http://en.wikipedia.org/wiki/Push_technology#Long_polling) 方式 的 AJAX 聊天室。如果你使用到了 long polling,你可能需要復寫`on_connection_close()`, 這樣你可以在客戶連接關閉以后做相關的清理動作。(請查看該方法的代碼文檔,以防誤用。)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看