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
142fad4b
Kaydet (Commit)
142fad4b
authored
Mar 20, 2011
tarafından
Brian Quinlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use WeakSets rather than manual pruning to prevent unbounded growth of dead thread references.
üst
833d9120
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
40 deletions
+8
-40
process.py
Lib/concurrent/futures/process.py
+4
-19
thread.py
Lib/concurrent/futures/thread.py
+4
-21
No files found.
Lib/concurrent/futures/process.py
Dosyayı görüntüle @
142fad4b
...
...
@@ -66,28 +66,14 @@ import weakref
# workers to exit when their work queues are empty and then waits until the
# threads/processes finish.
_
thread_references
=
s
et
()
_
live_threads
=
weakref
.
WeakS
et
()
_shutdown
=
False
def
_python_exit
():
global
_shutdown
_shutdown
=
True
for
thread_reference
in
_thread_references
:
thread
=
thread_reference
()
if
thread
is
not
None
:
thread
.
join
()
def
_remove_dead_thread_references
():
"""Remove inactive threads from _thread_references.
Should be called periodically to prevent memory leaks in scenarios such as:
>>> while True:
>>> ... t = ThreadPoolExecutor(max_workers=5)
>>> ... t.map(int, ['1', '2', '3', '4', '5'])
"""
for
thread_reference
in
set
(
_thread_references
):
if
thread_reference
()
is
None
:
_thread_references
.
discard
(
thread_reference
)
for
thread
in
_live_threads
:
thread
.
join
()
# Controls how many more calls than processes will be queued in the call queue.
# A smaller number will mean that processes spend more time idle waiting for
...
...
@@ -279,7 +265,6 @@ class ProcessPoolExecutor(_base.Executor):
worker processes will be created as the machine has processors.
"""
_check_system_limits
()
_remove_dead_thread_references
()
if
max_workers
is
None
:
self
.
_max_workers
=
multiprocessing
.
cpu_count
()
...
...
@@ -316,7 +301,7 @@ class ProcessPoolExecutor(_base.Executor):
self
.
_shutdown_process_event
))
self
.
_queue_management_thread
.
daemon
=
True
self
.
_queue_management_thread
.
start
()
_
thread_references
.
add
(
weakref
.
ref
(
self
.
_queue_management_thread
)
)
_
live_threads
.
add
(
self
.
_queue_management_thread
)
def
_adjust_process_count
(
self
):
for
_
in
range
(
len
(
self
.
_processes
),
self
.
_max_workers
):
...
...
Lib/concurrent/futures/thread.py
Dosyayı görüntüle @
142fad4b
...
...
@@ -25,29 +25,14 @@ import weakref
# workers to exit when their work queues are empty and then waits until the
# threads finish.
_
thread_references
=
s
et
()
_
live_threads
=
weakref
.
WeakS
et
()
_shutdown
=
False
def
_python_exit
():
global
_shutdown
_shutdown
=
True
for
thread_reference
in
_thread_references
:
thread
=
thread_reference
()
if
thread
is
not
None
:
thread
.
join
()
def
_remove_dead_thread_references
():
"""Remove inactive threads from _thread_references.
Should be called periodically to prevent memory leaks in scenarios such as:
>>> while True:
... t = ThreadPoolExecutor(max_workers=5)
... t.map(int, ['1', '2', '3', '4', '5'])
"""
for
thread_reference
in
set
(
_thread_references
):
if
thread_reference
()
is
None
:
_thread_references
.
discard
(
thread_reference
)
for
thread
in
_live_threads
:
thread
.
join
()
atexit
.
register
(
_python_exit
)
class
_WorkItem
(
object
):
...
...
@@ -95,8 +80,6 @@ class ThreadPoolExecutor(_base.Executor):
max_workers: The maximum number of threads that can be used to
execute the given calls.
"""
_remove_dead_thread_references
()
self
.
_max_workers
=
max_workers
self
.
_work_queue
=
queue
.
Queue
()
self
.
_threads
=
set
()
...
...
@@ -125,7 +108,7 @@ class ThreadPoolExecutor(_base.Executor):
t
.
daemon
=
True
t
.
start
()
self
.
_threads
.
add
(
t
)
_
thread_references
.
add
(
weakref
.
ref
(
t
)
)
_
live_threads
.
add
(
t
)
def
shutdown
(
self
,
wait
=
True
):
with
self
.
_shutdown_lock
:
...
...
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