我输入了AsyncHTTPClient
sample code来自tornado网站的交互式Python解释器,但异步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
作为 Web 服务器处理的一部分吗?
最佳答案
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()
关于python - 如何在没有服务器的情况下立即执行 AsyncHTTPClient() (使用交互式解释器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18801879/