[Python-checkins] cpython: asyncio: fix 2nd task example

victor.stinner python-checkins at python.org
Tue Dec 10 02:51:24 CET 2013


http://hg.python.org/cpython/rev/240dc7622087
changeset:   87866:240dc7622087
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Dec 10 02:51:05 2013 +0100
summary:
  asyncio: fix 2nd task example

files:
  Doc/library/asyncio-task.rst |  30 ++++++++++++------------
  1 files changed, 15 insertions(+), 15 deletions(-)


diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -315,13 +315,13 @@
     import asyncio
 
     @asyncio.coroutine
-    def factorial(task, n):
+    def factorial(name, number):
         f = 1
-        for i in range(2, n+1):
-            print("[%s] Compute factorial(%s)..." % (task, i))
+        for i in range(2, number+1):
+            print("Task %s: Compute factorial(%s)..." % (name, i))
             yield from asyncio.sleep(1)
-            f *= n
-        print("[%s] factorial(%s) = %s" % (task, n, f))
+            f *= i
+        print("Task %s: factorial(%s) = %s" % (name, number, f))
 
     task_a = asyncio.Task(factorial("A", 2))
     task_b = asyncio.Task(factorial("B", 3))
@@ -333,17 +333,17 @@
 
 Output::
 
-    [A] Compute factorial(2)...
-    [B] Compute factorial(2)...
-    [C] Compute factorial(2)...
-    [A] factorial(2) = 2
-    [B] Compute factorial(3)...
-    [C] Compute factorial(3)...
-    [B] factorial(3) = 9
-    [C] Compute factorial(4)...
-    [C] factorial(4) = 64
+    Task A: Compute factorial(2)...
+    Task B: Compute factorial(2)...
+    Task C: Compute factorial(2)...
+    Task A: factorial(2) = 2
+    Task B: Compute factorial(3)...
+    Task C: Compute factorial(3)...
+    Task B: factorial(3) = 6
+    Task C: Compute factorial(4)...
+    Task C: factorial(4) = 24
 
-When a task is created, it is automatically scheduled for execution. The event
+A task is automatically scheduled for execution when it is created. The event
 loop stops when all tasks are done.
 
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list