3
3
from test import support
4
4
from test .support import (verbose , refcount_test ,
5
5
cpython_only , requires_subprocess ,
6
- requires_gil_enabled )
6
+ requires_gil_enabled , suppress_immortalization ,
7
+ Py_GIL_DISABLED )
7
8
from test .support .import_helper import import_module
8
9
from test .support .os_helper import temp_dir , TESTFN , unlink
9
10
from test .support .script_helper import assert_python_ok , make_script
@@ -109,6 +110,7 @@ def test_tuple(self):
109
110
del l
110
111
self .assertEqual (gc .collect (), 2 )
111
112
113
+ @suppress_immortalization ()
112
114
def test_class (self ):
113
115
class A :
114
116
pass
@@ -117,6 +119,7 @@ class A:
117
119
del A
118
120
self .assertNotEqual (gc .collect (), 0 )
119
121
122
+ @suppress_immortalization ()
120
123
def test_newstyleclass (self ):
121
124
class A (object ):
122
125
pass
@@ -133,6 +136,7 @@ class A:
133
136
del a
134
137
self .assertNotEqual (gc .collect (), 0 )
135
138
139
+ @suppress_immortalization ()
136
140
def test_newinstance (self ):
137
141
class A (object ):
138
142
pass
@@ -219,6 +223,7 @@ class B(object):
219
223
self .fail ("didn't find obj in garbage (finalizer)" )
220
224
gc .garbage .remove (obj )
221
225
226
+ @suppress_immortalization ()
222
227
def test_function (self ):
223
228
# Tricky: f -> d -> f, code should call d.clear() after the exec to
224
229
# break the cycle.
@@ -561,6 +566,7 @@ def test_get_referents(self):
561
566
562
567
self .assertEqual (gc .get_referents (1 , 'a' , 4j ), [])
563
568
569
+ @suppress_immortalization ()
564
570
def test_is_tracked (self ):
565
571
# Atomic built-in types are not tracked, user-defined objects and
566
572
# mutable containers are.
@@ -598,7 +604,9 @@ class UserFloatSlots(float):
598
604
class UserIntSlots (int ):
599
605
__slots__ = ()
600
606
601
- self .assertTrue (gc .is_tracked (gc ))
607
+ if not Py_GIL_DISABLED :
608
+ # gh-117783: modules may be immortalized in free-threaded build
609
+ self .assertTrue (gc .is_tracked (gc ))
602
610
self .assertTrue (gc .is_tracked (UserClass ))
603
611
self .assertTrue (gc .is_tracked (UserClass ()))
604
612
self .assertTrue (gc .is_tracked (UserInt ()))
@@ -1347,6 +1355,10 @@ def callback(ignored):
1347
1355
junk = []
1348
1356
i = 0
1349
1357
detector = GC_Detector ()
1358
+ if Py_GIL_DISABLED :
1359
+ # The free-threaded build doesn't have multiple generations, so
1360
+ # just trigger a GC manually.
1361
+ gc .collect ()
1350
1362
while not detector .gc_happened :
1351
1363
i += 1
1352
1364
if i > 10000 :
@@ -1415,6 +1427,10 @@ def __del__(self):
1415
1427
detector = GC_Detector ()
1416
1428
junk = []
1417
1429
i = 0
1430
+ if Py_GIL_DISABLED :
1431
+ # The free-threaded build doesn't have multiple generations, so
1432
+ # just trigger a GC manually.
1433
+ gc .collect ()
1418
1434
while not detector .gc_happened :
1419
1435
i += 1
1420
1436
if i > 10000 :
0 commit comments