From 5234dbfec999e56cea0d2037ee9fb9736bc755fb Mon Sep 17 00:00:00 2001 From: stepan Date: Wed, 28 Jan 2026 16:16:01 +0100 Subject: [PATCH] Run GC only once the timeout exceeds 4s in Windows os_helper.py _waitfor to reduce overhead --- graalpython/lib-python/3/test/support/os_helper.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/graalpython/lib-python/3/test/support/os_helper.py b/graalpython/lib-python/3/test/support/os_helper.py index 959daef2d0..612bce6872 100644 --- a/graalpython/lib-python/3/test/support/os_helper.py +++ b/graalpython/lib-python/3/test/support/os_helper.py @@ -332,8 +332,6 @@ def unlink(filename): if sys.platform.startswith("win"): def _waitfor(func, pathname, waitall=False): - # GraalPy change: run GC to ensure all handles are closed - support.gc_collect() # Perform the operation func(pathname) # Now setup the wait loop @@ -350,9 +348,7 @@ def _waitfor(func, pathname, waitall=False): # required when contention occurs. timeout = 0.001 # GraalPy change: increase timeout to account for our overloaded machines - # and run GC to ensure all handles are closed while timeout < 120.0: - support.gc_collect() # Note we are only testing for the existence of the file(s) in # the contents of the directory regardless of any security or # access rights. If we have made it this far, we have sufficient @@ -366,6 +362,10 @@ def _waitfor(func, pathname, waitall=False): # Increase the timeout and try again time.sleep(timeout) timeout *= 2 + # GraalPy change: if we are this far, also run GC to ensure + # all handles are closed + if timeout > 4.0: + support.gc_collect() warnings.warn('tests may fail, delete still pending for ' + pathname, RuntimeWarning, stacklevel=4)