#! /usr/bin/env python
# -*- coding: utf-8 -*-
import tornado.httpserver
import tornado.httpclient
import tornado.web
import tornado.options
from adisp import async, process
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
class MainHandler(tornado.web.RequestHandler):
@async
def fetch(self, url, callback):
http = tornado.httpclient.AsyncHTTPClient()
http.fetch(url, self.async_callback(callback))
@tornado.web.asynchronous
@process
def get(self, url):
response = yield self.fetch(url)
if response.error:
raise tornado.web.HTTPError(500, 'Ooops')
self.write(response.body)
self.finish()
application = tornado.web.Application([
(r"/(.*)", MainHandler),
])
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()