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
4aa21aa5
Kaydet (Commit)
4aa21aa5
authored
Agu 09, 2002
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Test finalizers and GC from inside __del__ for new classes.
üst
bffb2efe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
test_gc.py
Lib/test/test_gc.py
+41
-0
No files found.
Lib/test/test_gc.py
Dosyayı görüntüle @
4aa21aa5
...
@@ -124,6 +124,30 @@ def test_finalizer():
...
@@ -124,6 +124,30 @@ def test_finalizer():
raise
TestFailed
,
"didn't find obj in garbage (finalizer)"
raise
TestFailed
,
"didn't find obj in garbage (finalizer)"
gc
.
garbage
.
remove
(
obj
)
gc
.
garbage
.
remove
(
obj
)
def
test_finalizer_newclass
():
# A() is uncollectable if it is part of a cycle, make sure it shows up
# in gc.garbage.
class
A
(
object
):
def
__del__
(
self
):
pass
class
B
(
object
):
pass
a
=
A
()
a
.
a
=
a
id_a
=
id
(
a
)
b
=
B
()
b
.
b
=
b
gc
.
collect
()
del
a
del
b
expect_nonzero
(
gc
.
collect
(),
"finalizer"
)
for
obj
in
gc
.
garbage
:
if
id
(
obj
)
==
id_a
:
del
obj
.
a
break
else
:
raise
TestFailed
,
"didn't find obj in garbage (finalizer)"
gc
.
garbage
.
remove
(
obj
)
def
test_function
():
def
test_function
():
# Tricky: f -> d -> f, code should call d.clear() after the exec to
# Tricky: f -> d -> f, code should call d.clear() after the exec to
# break the cycle.
# break the cycle.
...
@@ -177,6 +201,21 @@ def test_del():
...
@@ -177,6 +201,21 @@ def test_del():
gc
.
disable
()
gc
.
disable
()
apply
(
gc
.
set_threshold
,
thresholds
)
apply
(
gc
.
set_threshold
,
thresholds
)
def
test_del_newclass
():
# __del__ methods can trigger collection, make this to happen
thresholds
=
gc
.
get_threshold
()
gc
.
enable
()
gc
.
set_threshold
(
1
)
class
A
(
object
):
def
__del__
(
self
):
dir
(
self
)
a
=
A
()
del
a
gc
.
disable
()
apply
(
gc
.
set_threshold
,
thresholds
)
class
Ouch
:
class
Ouch
:
n
=
0
n
=
0
def
__del__
(
self
):
def
__del__
(
self
):
...
@@ -225,7 +264,9 @@ def test_all():
...
@@ -225,7 +264,9 @@ def test_all():
run_test
(
"functions"
,
test_function
)
run_test
(
"functions"
,
test_function
)
run_test
(
"frames"
,
test_frame
)
run_test
(
"frames"
,
test_frame
)
run_test
(
"finalizers"
,
test_finalizer
)
run_test
(
"finalizers"
,
test_finalizer
)
run_test
(
"finalizers (new class)"
,
test_finalizer_newclass
)
run_test
(
"__del__"
,
test_del
)
run_test
(
"__del__"
,
test_del
)
run_test
(
"__del__ (new class)"
,
test_del_newclass
)
run_test
(
"saveall"
,
test_saveall
)
run_test
(
"saveall"
,
test_saveall
)
run_test
(
"trashcan"
,
test_trashcan
)
run_test
(
"trashcan"
,
test_trashcan
)
...
...
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