dldx0 2016-09-05
tornado 安装
1.git下载tornado
git clone https://github.com/tornadoweb/tornado.gie
2. 进入下载tornado 文件夹
cd tornado
3. bulid tornado
python setup.py build
4.install tornado
python setup.py install
-------------------------------------------------------------------------------------------------------------
python setup.py install 需要pipy连接外网资源,没有外网的虚机是不能安装成功的
-------------------------------------------------------------------------------------------------------------
用tornado 写一个循环访问urldemo
import tornado.ioloop
from tornado.httpclient import AsyncHTTPClient
def handle_request(response):
if response.error:
print ("Error:", response.error)
else:
print(response.body)
#param = {"msg":"111"}
#param["img_msg"] = open("t.jpg",'r',encoding='utf-8')
url = 'http://10.58.100.90/jsondatedemo.txt'
i = 1
#print(param)
#req = tornado.httpclient.HTTPRequest(url, 'POST', body=str(param))
req = tornado.httpclient.HTTPRequest(url, 'GET')
http_client = AsyncHTTPClient()
while i<10:
i += 1
http_client.fetch(req, handle_request)
tornado.ioloop.IOLoop.instance().start()