]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #29407: Remove redundant ensure_future() calls in factorial example
authorBerker Peksag <berker.peksag@gmail.com>
Wed, 1 Feb 2017 19:37:16 +0000 (22:37 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Wed, 1 Feb 2017 19:37:16 +0000 (22:37 +0300)
Doc/library/asyncio-task.rst

index 9bff1c4140b237e89d9aba53c46dc4499afc57a3..90cb9c364ff217285bf4b84b720ec90aa22c99ba 100644 (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::