Issue #29407: Merge from 3.5

This commit is contained in:
Berker Peksag 2017-02-01 22:37:49 +03:00
commit c6fe419d1b
1 changed files with 7 additions and 8 deletions

View File

@ -472,21 +472,20 @@ Example executing 3 tasks (A, B, C) in parallel::
import asyncio
@asyncio.coroutine
def factorial(name, number):
async def factorial(name, number):
f = 1
for i in range(2, number+1):
print("Task %s: Compute factorial(%s)..." % (name, i))
yield from asyncio.sleep(1)
await asyncio.sleep(1)
f *= i
print("Task %s: factorial(%s) = %s" % (name, number, f))
loop = asyncio.get_event_loop()
tasks = [
asyncio.ensure_future(factorial("A", 2)),
asyncio.ensure_future(factorial("B", 3)),
asyncio.ensure_future(factorial("C", 4))]
loop.run_until_complete(asyncio.gather(*tasks))
loop.run_until_complete(asyncio.gather(
factorial("A", 2),
factorial("B", 3),
factorial("C", 4),
))
loop.close()
Output::