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
a885c152
Kaydet (Commit)
a885c152
authored
Şub 23, 2008
tarafından
Jeffrey Yasskin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Followup to r61011: Also avoid the reference cycle when the Thread's target
raises an exception.
üst
3414ea9e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
test_threading.py
Lib/test/test_threading.py
+11
-3
threading.py
Lib/threading.py
+7
-5
No files found.
Lib/test/test_threading.py
Dosyayı görüntüle @
a885c152
...
...
@@ -256,23 +256,31 @@ class ThreadTests(unittest.TestCase):
def
test_no_refcycle_through_target
(
self
):
class
RunSelfFunction
(
object
):
def
__init__
(
self
):
def
__init__
(
self
,
should_raise
):
# The links in this refcycle from Thread back to self
# should be cleaned up when the thread completes.
self
.
should_raise
=
should_raise
self
.
thread
=
threading
.
Thread
(
target
=
self
.
_run
,
args
=
(
self
,),
kwargs
=
{
'yet_another'
:
self
})
self
.
thread
.
start
()
def
_run
(
self
,
other_ref
,
yet_another
):
pass
if
self
.
should_raise
:
raise
SystemExit
cyclic_object
=
RunSelfFunction
()
cyclic_object
=
RunSelfFunction
(
should_raise
=
False
)
weak_cyclic_object
=
weakref
.
ref
(
cyclic_object
)
cyclic_object
.
thread
.
join
()
del
cyclic_object
self
.
assertEquals
(
None
,
weak_cyclic_object
())
raising_cyclic_object
=
RunSelfFunction
(
should_raise
=
True
)
weak_raising_cyclic_object
=
weakref
.
ref
(
raising_cyclic_object
)
raising_cyclic_object
.
thread
.
join
()
del
raising_cyclic_object
self
.
assertEquals
(
None
,
weak_raising_cyclic_object
())
class
ThreadingExceptionTests
(
unittest
.
TestCase
):
# A RuntimeError should be raised if Thread.start() is called
...
...
Lib/threading.py
Dosyayı görüntüle @
a885c152
...
...
@@ -442,11 +442,13 @@ class Thread(_Verbose):
_sleep
(
0.000001
)
# 1 usec, to let the thread run (Solaris hack)
def
run
(
self
):
if
self
.
__target
:
self
.
__target
(
*
self
.
__args
,
**
self
.
__kwargs
)
# Avoid a refcycle if the thread is running a function with an
# argument that has a member that points to the thread.
del
self
.
__target
,
self
.
__args
,
self
.
__kwargs
try
:
if
self
.
__target
:
self
.
__target
(
*
self
.
__args
,
**
self
.
__kwargs
)
finally
:
# Avoid a refcycle if the thread is running a function with
# an argument that has a member that points to the thread.
del
self
.
__target
,
self
.
__args
,
self
.
__kwargs
def
__bootstrap
(
self
):
# Wrapper around the real bootstrap code that ignores
...
...
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