import asyncio,time from collections import defaultdict from pprint import pprint collect=defaultdict(list) #######创建处理一个对象的方法,并返回期物 async def dealone(chunk): return 'Receive %d at %.5f seconds' % (chunk,time.time()) #######委派给dealone处理,并获取处理结果 async def submitor(chunk): future=await dealone(chunk) collect['res'].append(future) chunks=range(10) loop = asyncio.get_event_loop() tasks=asyncio.wait([submitor(chunk) for chunk in chunks]) loop.run_until_complete(tasks) pprint(collect['res'])