使用asynchttpclient的botocore子类
botocore-tornado的Python项目详细描述
此模块提供botocore的子类 使用Tornado AsynchttpClient发出请求的类。至于 可能的话,api与botocoreapi保持不变,唯一的区别是 当http请求为 完成。
安装
pip install botocore-tornado
示例
将文件上载到s3:
importbotocore.sessionsession=botocore.session.get_session()s3=session.get_service('s3')endpoint=s3.get_endpoint(region)fp=open('./testfile.txt','rb')operation=s3.get_operation('PutObject')http_response,response_data=operation.call(endpoint,bucket=bucket,key=key+'/'+filename,body=fp)
使用Botocore Tornado:
fromtornado.ioloopimportIOLoopfromtornadoimportgenimportbotocore_tornado.session@gen.coroutinedefmain_async():session=botocore_tornado.session.get_session()s3=session.get_service('s3')endpoint=s3.get_endpoint(region)fp=open('./testfile.txt','rb')operation=s3.get_operation('PutObject')http_response,response_data=yieldoperation.call(endpoint,bucket=bucket,key=key+'/'+filename,body=fp)printresponse_dataIOLoop.instance().run_sync(main_async)