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
3ec60183
Kaydet (Commit)
3ec60183
authored
Kas 17, 2010
tarafından
Brian Quinlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Removes an inefficient spin loop in as_completed
üst
42dd524c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
6 deletions
+35
-6
_base.py
Lib/concurrent/futures/_base.py
+35
-6
No files found.
Lib/concurrent/futures/_base.py
Dosyayı görüntüle @
3ec60183
...
...
@@ -12,6 +12,7 @@ import time
FIRST_COMPLETED
=
'FIRST_COMPLETED'
FIRST_EXCEPTION
=
'FIRST_EXCEPTION'
ALL_COMPLETED
=
'ALL_COMPLETED'
_AS_COMPLETED
=
'_AS_COMPLETED'
# Possible future states (for internal use by the futures package).
PENDING
=
'PENDING'
...
...
@@ -70,8 +71,30 @@ class _Waiter(object):
def
add_cancelled
(
self
,
future
):
self
.
finished_futures
.
append
(
future
)
class
_AsCompletedWaiter
(
_Waiter
):
"""Used by as_completed()."""
def
__init__
(
self
):
super
(
_AsCompletedWaiter
,
self
)
.
__init__
()
self
.
lock
=
threading
.
Lock
()
def
add_result
(
self
,
future
):
with
self
.
lock
:
super
(
_AsCompletedWaiter
,
self
)
.
add_result
(
future
)
self
.
event
.
set
()
def
add_exception
(
self
,
future
):
with
self
.
lock
:
super
(
_AsCompletedWaiter
,
self
)
.
add_exception
(
future
)
self
.
event
.
set
()
def
add_cancelled
(
self
,
future
):
with
self
.
lock
:
super
(
_AsCompletedWaiter
,
self
)
.
add_cancelled
(
future
)
self
.
event
.
set
()
class
_FirstCompletedWaiter
(
_Waiter
):
"""Used by wait(return_when=FIRST_COMPLETED)
and as_completed()
."""
"""Used by wait(return_when=FIRST_COMPLETED)."""
def
add_result
(
self
,
future
):
super
()
.
add_result
(
future
)
...
...
@@ -128,7 +151,9 @@ class _AcquireFutures(object):
future
.
_condition
.
release
()
def
_create_and_install_waiters
(
fs
,
return_when
):
if
return_when
==
FIRST_COMPLETED
:
if
return_when
==
_AS_COMPLETED
:
waiter
=
_AsCompletedWaiter
()
elif
return_when
==
FIRST_COMPLETED
:
waiter
=
_FirstCompletedWaiter
()
else
:
pending_count
=
sum
(
...
...
@@ -171,7 +196,7 @@ def as_completed(fs, timeout=None):
f
for
f
in
fs
if
f
.
_state
in
[
CANCELLED_AND_NOTIFIED
,
FINISHED
])
pending
=
set
(
fs
)
-
finished
waiter
=
_create_and_install_waiters
(
fs
,
FIRST
_COMPLETED
)
waiter
=
_create_and_install_waiters
(
fs
,
_AS
_COMPLETED
)
try
:
for
future
in
finished
:
...
...
@@ -187,11 +212,15 @@ def as_completed(fs, timeout=None):
'
%
d (of
%
d) futures unfinished'
%
(
len
(
pending
),
len
(
fs
)))
waiter
.
event
.
wait
(
timeout
)
waiter
.
event
.
wait
(
wait_timeout
)
with
waiter
.
lock
:
finished
=
waiter
.
finished_futures
waiter
.
finished_futures
=
[]
waiter
.
event
.
clear
()
for
future
in
waiter
.
finished_futures
[:]
:
for
future
in
finished
:
yield
future
waiter
.
finished_futures
.
remove
(
future
)
pending
.
remove
(
future
)
finally
:
...
...
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