task是可以理解为单个coroutine,经过ensure_future方法处理而形成,而众多task所组成的集合经过asyncio.gather处理而形成一个future. 再不精确的粗略的说,future就是存放着众多task或future的容器. 而task又是future的子类,所以不管是task还是future还是coreture都可以看成是一个广义的携程,future无非是一个内部包含众多携程的大携程而已,await后面,task,coroture,future都可以接. en
from :http://masnun.com/2015/11/20/python-asyncio-future-task-and-the-event-loop.html Event Loop On any platform, when we want to do something asynchronously, it usually involves an event loop. An event loop is a loop that can register tasks to be ex
#!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from random import randint @asyncio.coroutine def factorial(number): f = 1 for i in range(2, number+1): print("Asyncio.Task: Compute factorial(%s)" % (i)) y