@@ -114,12 +114,15 @@ def runtest_refleak(test_name, test_func,
114114 rc_deltas = array ('q' , [0 ]) * repcount
115115 alloc_deltas = array ('q' , [0 ]) * repcount
116116 fd_deltas = array ('q' , [0 ]) * repcount
117+ handle_deltas = array ('q' , [0 ]) * repcount
117118 getallocatedblocks = sys .getallocatedblocks
118119 gettotalrefcount = sys .gettotalrefcount
119120 getunicodeinternedsize = sys .getunicodeinternedsize
120121 fd_count = os_helper .fd_count
122+ handle_count = os_helper .handle_count
121123 # initialize variables to make pyflakes quiet
122124 rc_before = alloc_before = fd_before = interned_immortal_before = 0
125+ handle_before = 0
123126
124127 if not quiet :
125128 print ("beginning" , repcount , "repetitions. Showing number of leaks "
@@ -154,13 +157,17 @@ def runtest_refleak(test_name, test_func,
154157 alloc_after = getallocatedblocks () - interned_immortal_after
155158 rc_after = gettotalrefcount ()
156159 fd_after = fd_count ()
160+ handle_after = handle_count ()
157161
158162 rc_deltas [i ] = rc_after - rc_before
159163 alloc_deltas [i ] = alloc_after - alloc_before
160164 fd_deltas [i ] = fd_after - fd_before
165+ handle_deltas [i ] = handle_after - handle_before
161166
162167 if not quiet :
163- total_leaks = max (rc_deltas [i ], alloc_deltas [i ], fd_deltas [i ])
168+ # use max, not sum, so total_leaks is one of the pooled ints
169+ total_leaks = max (rc_deltas [i ], alloc_deltas [i ],
170+ fd_deltas [i ], handle_deltas [i ])
164171 if total_leaks <= 0 :
165172 symbol = '.'
166173 elif total_leaks < 10 :
@@ -178,18 +185,29 @@ def runtest_refleak(test_name, test_func,
178185 alloc_before = alloc_after
179186 rc_before = rc_after
180187 fd_before = fd_after
188+ handle_before = handle_after
181189 interned_immortal_before = interned_immortal_after
182190
183191 restore_support_xml (xml_filename )
184192
185193 if not quiet :
186194 print (file = sys .stderr )
187195
196+ if ('multiprocessing' in test_name
197+ or 'concurrent_futures' in test_name ):
198+ # gh-154208: Disable check for Windows handle leaks when
199+ # multiprocessing is used. There is a known race condition in
200+ # multiprocessing causing handle leak. Disable the multiprocessing
201+ # tests to be able to check for leaks for all other tests.
202+ for i in range (len (handle_deltas )):
203+ handle_deltas [i ] = 0
204+
188205 failed = False
189206 for raw_deltas , item_name in [
190207 (rc_deltas , 'references' ),
191208 (alloc_deltas , 'memory blocks' ),
192- (fd_deltas , 'file descriptors' )
209+ (fd_deltas , 'file descriptors' ),
210+ (handle_deltas , 'handles' ),
193211 ]:
194212 # Ignore warmup runs; convert to a list for reporting
195213 deltas = list (raw_deltas [warmups :])
0 commit comments