Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
34f2946a
Kaydet (Commit)
34f2946a
authored
Ara 10, 2013
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
asyncio: fix 2nd task example
üst
dbd8950b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
asyncio-task.rst
Doc/library/asyncio-task.rst
+16
-16
No files found.
Doc/library/asyncio-task.rst
Dosyayı görüntüle @
34f2946a
...
@@ -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