Skip to content

Commit d5adb63

Browse files
committed
Issue python#29407: Remove redundant ensure_future() calls in factorial example
1 parent 137b5a2 commit d5adb63

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Doc/library/asyncio-task.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,21 +472,20 @@ Example executing 3 tasks (A, B, C) in parallel::
472472

473473
import asyncio
474474

475-
@asyncio.coroutine
476-
def factorial(name, number):
475+
async def factorial(name, number):
477476
f = 1
478477
for i in range(2, number+1):
479478
print("Task %s: Compute factorial(%s)..." % (name, i))
480-
yield from asyncio.sleep(1)
479+
await asyncio.sleep(1)
481480
f *= i
482481
print("Task %s: factorial(%s) = %s" % (name, number, f))
483482

484483
loop = asyncio.get_event_loop()
485-
tasks = [
486-
asyncio.ensure_future(factorial("A", 2)),
487-
asyncio.ensure_future(factorial("B", 3)),
488-
asyncio.ensure_future(factorial("C", 4))]
489-
loop.run_until_complete(asyncio.gather(*tasks))
484+
loop.run_until_complete(asyncio.gather(
485+
factorial("A", 2),
486+
factorial("B", 3),
487+
factorial("C", 4),
488+
))
490489
loop.close()
491490

492491
Output::

0 commit comments

Comments
 (0)