我在一个交互式python解释器中从龙卷风的网站输入AsyncHTTPClient
sample code但是从不执行异步HTTP请求。
def handle_request(response):
if response.error:
print "Error:", response.error
else:
print response.body
http_client = AsyncHTTPClient()
http_client.fetch("http://www.google.com/", handle_request)
# handle_request function is never executed (nothing is printed)
我是否可以将AsyncHTTPClient
用作网络服务器处理的一部分?
答案 0 :(得分:3)
from tornado import ioloop
from tornado.httpclient import AsyncHTTPClient
def handle_request(response):
if response.error:
print "Error:", response.error
else:
print response.body
ioloop.IOLoop.instance().stop()
http_client = AsyncHTTPClient()
http_client.fetch("http://www.google.com/", handle_request)
ioloop.IOLoop.instance().start()