Tornado AsyncHTTPClient

架了個tornado服務器,原本想用徹底異步,後來發現客戶端這麼玩難度也很大,這個AsyncHTTPClient也是須要須要ioloop.start()這就過重了。服務器

基本操做步驟仍是記錄下吧異步

r=self.http_client.fetch(REQ_PRICING_OPTION, method="POST", body=jd(data),callback=self.handle_request)函數

這是返回一個future,r能夠add callback的,也能夠直接寫在函數裏面tornado

 

    def handle_request(self,response):
        #response=resp.result()
        if response.error:
            print "Error:", response.error
        else:
            data=jl(response.body)["data"]
            if self.ee is not None:
                logger.info('return pricing greeks')
                self.ee.put(Event(EDS_HAHA,data))
            print data
            #time.sleep(3)
            #self.pricing_option({})

徹底異步的設計了,做罷,仍是urllib直接取數據了。oop

相關文章
相關標籤/搜索