diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-12-10 01:51:05 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-12-10 01:51:05 (GMT) |
commit | 34f2946a11b4d91a54da1a4d257ab3dd2b828ade (patch) | |
tree | a545fe5531994e0ea94693c0a843c5b90fd9e0fb /Doc/library | |
parent | dbd8950b288cb735ca040e3b9d3a5db0a80f17a4 (diff) | |
download | cpython-34f2946a11b4d91a54da1a4d257ab3dd2b828ade.zip cpython-34f2946a11b4d91a54da1a4d257ab3dd2b828ade.tar.gz cpython-34f2946a11b4d91a54da1a4d257ab3dd2b828ade.tar.bz2 |
asyncio: fix 2nd task example
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/asyncio-task.rst | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 38cf333..f42aaa7 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -315,13 +315,13 @@ Example executing 3 tasks (A, B, C) in parallel:: 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 @@ Example executing 3 tasks (A, B, C) in parallel:: 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 - -When a task is created, it is automatically scheduled for execution. The event + 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 + +A task is automatically scheduled for execution when it is created. The event loop stops when all tasks are done. |