7
7
Py_GIL_DISABLED )
8
8
from test .support .import_helper import import_module
9
9
from test .support .os_helper import temp_dir , TESTFN , unlink
10
- from test .support .script_helper import assert_python_ok , make_script
10
+ from test .support .script_helper import assert_python_ok , make_script , run_test_script
11
11
from test .support import threading_helper , gc_threshold
12
12
13
13
import gc
@@ -1127,64 +1127,14 @@ def test_something(self):
1127
1127
1128
1128
1129
1129
class IncrementalGCTests (unittest .TestCase ):
1130
-
1131
- def setUp (self ):
1132
- # Reenable GC as it is disabled module-wide
1133
- gc .enable ()
1134
-
1135
- def tearDown (self ):
1136
- gc .disable ()
1137
-
1138
1130
@unittest .skipIf (_testinternalcapi is None , "requires _testinternalcapi" )
1139
1131
@requires_gil_enabled ("Free threading does not support incremental GC" )
1140
- # Use small increments to emulate longer running process in a shorter time
1141
- @gc_threshold (200 , 10 )
1142
1132
def test_incremental_gc_handles_fast_cycle_creation (self ):
1143
-
1144
- class LinkedList :
1145
-
1146
- #Use slots to reduce number of implicit objects
1147
- __slots__ = "next" , "prev" , "surprise"
1148
-
1149
- def __init__ (self , next = None , prev = None ):
1150
- self .next = next
1151
- if next is not None :
1152
- next .prev = self
1153
- self .prev = prev
1154
- if prev is not None :
1155
- prev .next = self
1156
-
1157
- def make_ll (depth ):
1158
- head = LinkedList ()
1159
- for i in range (depth ):
1160
- head = LinkedList (head , head .prev )
1161
- return head
1162
-
1163
- head = make_ll (1000 )
1164
- count = 1000
1165
-
1166
- # There will be some objects we aren't counting,
1167
- # e.g. the gc stats dicts. This test checks
1168
- # that the counts don't grow, so we try to
1169
- # correct for the uncounted objects
1170
- # This is just an estimate.
1171
- CORRECTION = 20
1172
-
1173
- enabled = gc .isenabled ()
1174
- gc .enable ()
1175
- olds = []
1176
- initial_heap_size = _testinternalcapi .get_tracked_heap_size ()
1177
- for i in range (20_000 ):
1178
- newhead = make_ll (20 )
1179
- count += 20
1180
- newhead .surprise = head
1181
- olds .append (newhead )
1182
- if len (olds ) == 20 :
1183
- new_objects = _testinternalcapi .get_tracked_heap_size () - initial_heap_size
1184
- self .assertLess (new_objects , 27_000 , f"Heap growing. Reached limit after { i } iterations" )
1185
- del olds [:]
1186
- if not enabled :
1187
- gc .disable ()
1133
+ # Run this test in a fresh process. The number of alive objects (which can
1134
+ # be from unit tests run before this one) can influence how quickly cyclic
1135
+ # garbage is found.
1136
+ script = support .findfile ("_test_gc_fast_cycles.py" )
1137
+ run_test_script (script )
1188
1138
1189
1139
1190
1140
class GCCallbackTests (unittest .TestCase ):
0 commit comments