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
2c3865b2
Kaydet (Commit)
2c3865b2
authored
Ock 18, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Expand barrier example to show time-outs.
üst
e0f1f323
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
3.2.rst
Doc/whatsnew/3.2.rst
+20
-5
No files found.
Doc/whatsnew/3.2.rst
Dosyayı görüntüle @
2c3865b2
...
@@ -847,11 +847,6 @@ are suitable for use in loops. The separate *filling* and *draining* phases
...
@@ -847,11 +847,6 @@ are suitable for use in loops. The separate *filling* and *draining* phases
assure that all threads get released (drained) before any one of them can loop
assure that all threads get released (drained) before any one of them can loop
back and re-enter the barrier. The barrier fully resets after each cycle.
back and re-enter the barrier. The barrier fully resets after each cycle.
If any of the predecessor tasks can hang or be delayed, a barrier can be created
with an optional *timeout* parameter. Then if the timeout period elapses before
all the predecessor tasks reach the barrier point, all waiting threads are
released and a :exc:`~threading.BrokenBarrierError` exception is raised.
Example of using barriers::
Example of using barriers::
def get_votes(site):
def get_votes(site):
...
@@ -870,6 +865,26 @@ is similar to one with :meth:`threading.Thread.join`, but the threads stay alive
...
@@ -870,6 +865,26 @@ is similar to one with :meth:`threading.Thread.join`, but the threads stay alive
and continue to do work (summarizing ballots) after the barrier point is
and continue to do work (summarizing ballots) after the barrier point is
crossed.
crossed.
If any of the predecessor tasks can hang or be delayed, a barrier can be created
with an optional *timeout* parameter. Then if the timeout period elapses before
all the predecessor tasks reach the barrier point, all waiting threads are
released and a :exc:`~threading.BrokenBarrierError` exception is raised::
def get_votes(site):
ballots = conduct_election(site)
try:
all_polls_closed.wait(timeout = midnight - time.now())
except BrokenBarrerError:
lockbox = seal_ballots(ballots)
queue.put(lockbox)
else:
totals = summarize(ballots)
publish(site, totals)
In this example, the barrier enforces a more robust rule. If some election
sites do not finish before midnight, the barrier times-out and the ballots are
sealed and deposited in a queue for later handling.
See `Barrier Synchronization Patterns
See `Barrier Synchronization Patterns
<http://parlab.eecs.berkeley.edu/wiki/_media/patterns/paraplop_g1_3.pdf>`_ for
<http://parlab.eecs.berkeley.edu/wiki/_media/patterns/paraplop_g1_3.pdf>`_ for
more examples of how barriers can be used in parallel computing. Also, there is
more examples of how barriers can be used in parallel computing. Also, there is
...
...
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