Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a8a1aa1e
Commit
a8a1aa1e
authored
Dec 10, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asyncio: fix 2nd task example
parent
2ef9a04b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
Doc/library/asyncio-task.rst
Doc/library/asyncio-task.rst
+16
-16
No files found.
Doc/library/asyncio-task.rst
View file @
a8a1aa1e
...
@@ -315,13 +315,13 @@ Example executing 3 tasks (A, B, C) in parallel::
...
@@ -315,13 +315,13 @@ Example executing 3 tasks (A, B, C) in parallel::
import asyncio
import asyncio
@asyncio.coroutine
@asyncio.coroutine
def factorial(
task, n
):
def factorial(
name, number
):
f = 1
f = 1
for i in range(2, n+1):
for i in range(2, n
umber
+1):
print("
[%s] Compute factorial(%s)..." % (task
, i))
print("
Task %s: Compute factorial(%s)..." % (name
, i))
yield from asyncio.sleep(1)
yield from asyncio.sleep(1)
f *=
n
f *=
i
print("
[%s] factorial(%s) = %s" % (task, n
, f))
print("
Task %s: factorial(%s) = %s" % (name, number
, f))
task_a = asyncio.Task(factorial("A", 2))
task_a = asyncio.Task(factorial("A", 2))
task_b = asyncio.Task(factorial("B", 3))
task_b = asyncio.Task(factorial("B", 3))
...
@@ -333,17 +333,17 @@ Example executing 3 tasks (A, B, C) in parallel::
...
@@ -333,17 +333,17 @@ Example executing 3 tasks (A, B, C) in parallel::
Output::
Output::
[A]
Compute factorial(2)...
Task A:
Compute factorial(2)...
[B]
Compute factorial(2)...
Task B:
Compute factorial(2)...
[C]
Compute factorial(2)...
Task C:
Compute factorial(2)...
[A]
factorial(2) = 2
Task A:
factorial(2) = 2
[B]
Compute factorial(3)...
Task B:
Compute factorial(3)...
[C]
Compute factorial(3)...
Task C:
Compute factorial(3)...
[B] factorial(3) = 9
Task B: factorial(3) = 6
[C]
Compute factorial(4)...
Task C:
Compute factorial(4)...
[C] factorial(4) = 6
4
Task C: factorial(4) = 2
4
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.
loop stops when all tasks are done.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment