Created
          November 8, 2014 20:29 
        
      - 
      
- 
        Save alejandrobernardis/3dc544dfdc049a7ad996 to your computer and use it in GitHub Desktop. 
    Tornoado Gen: Test-1,999,991 ;)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import json | |
| from tornado import gen, ioloop | |
| from tornado.httpclient import AsyncHTTPClient, HTTPRequest | |
| from tornado.web import HTTPError | |
| AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient") | |
| class CoroutineModel(object): | |
| def _make_request(self): | |
| return HTTPRequest('https://google.com') | |
| def _make(self): | |
| req = self._make_request() | |
| return self.make(req) | |
| def make(self, req): | |
| return self._exe(req) | |
| @gen.coroutine | |
| def _exe(self, request): | |
| result = yield AsyncHTTPClient().fetch(request) | |
| raise gen.Return(result) | |
| @gen.coroutine | |
| def send(self): | |
| try: | |
| response = yield self._make() | |
| except Exception, e: | |
| response = e | |
| raise gen.Return(response) | |
| @gen.coroutine | |
| def run_coroutine(): | |
| print 'COROUTINE' | |
| print '*'*80 | |
| c = CoroutineModel() | |
| _ok = yield c.send() | |
| print json.dumps(_ok.headers, indent=4) | |
| if __name__ == '__main__': | |
| run_coroutine() | |
| ioloop.IOLoop.instance().start() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment