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
de311345
Kaydet (Commit)
de311345
authored
Mar 18, 2015
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #12155: Fix queue doc example to join threads
Use None as a sentinel to stop a worker.
üst
926ce700
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
13 deletions
+23
-13
queue.rst
Doc/library/queue.rst
+23
-13
No files found.
Doc/library/queue.rst
Dosyayı görüntüle @
de311345
...
@@ -158,22 +158,32 @@ fully processed by daemon consumer threads.
...
@@ -158,22 +158,32 @@ fully processed by daemon consumer threads.
Example of how to wait for enqueued tasks to be completed::
Example of how to wait for enqueued tasks to be completed::
def worker():
def worker():
while True:
while True:
item = q.get()
item = q.get()
do_work(item)
if item is None:
q.task_done()
break
do_work(item)
q = Queue()
q.task_done()
for i in range(num_worker_threads):
t = Thread(target=worker)
q = queue.Queue()
t.daemon = True
threads = []
for i in range(num_worker_threads):
t = threading.Thread(target=worker)
t.start()
t.start()
threads.append(t)
for item in source():
for item in source():
q.put(item)
q.put(item)
q.join() # block until all tasks are done
# block until all tasks are done
q.join()
# stop workers
for i in range(num_worker_threads):
q.put(None)
for t in threads:
t.join()
.. seealso::
.. seealso::
...
...
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