MCPcopy Index your code
hub / github.com/RustPython/RustPython / _waitfor

Function _waitfor

Lib/test/support/os_helper.py:378–413  ·  view source on GitHub ↗
(func, pathname, waitall=False)

Source from the content-addressed store, hash-verified

376
377if sys.platform.startswith("win"):
378 def _waitfor(func, pathname, waitall=False):
379 # Perform the operation
380 func(pathname)
381 # Now setup the wait loop
382 if waitall:
383 dirname = pathname
384 else:
385 dirname, name = os.path.split(pathname)
386 dirname = dirname or '.'
387 # Check for `pathname` to be removed from the filesystem.
388 # The exponential backoff of the timeout amounts to a total
389 # of ~1 second after which the deletion is probably an error
390 # anyway.
391 # Testing on an i7@4.3GHz shows that usually only 1 iteration is
392 # required when contention occurs.
393 timeout = 0.001
394 while timeout < 1.0:
395 # Note we are only testing for the existence of the file(s) in
396 # the contents of the directory regardless of any security or
397 # access rights. If we have made it this far, we have sufficient
398 # permissions to do that much using Python's equivalent of the
399 # Windows API FindFirstFile.
400 # Other Windows APIs can fail or give incorrect results when
401 # dealing with files that are pending deletion.
402 L = os.listdir(dirname)
403 if not (L if waitall else name in L):
404 return
405 # Increase the timeout and try again
406 time.sleep(timeout)
407 timeout *= 2
408 logging.getLogger(__name__).warning(
409 'tests may fail, delete still pending for %s',
410 pathname,
411 stack_info=True,
412 stacklevel=4,
413 )
414
415 def _unlink(filename):
416 _waitfor(os.unlink, filename)

Callers 4

_unlinkFunction · 0.85
_rmdirFunction · 0.85
_rmtree_innerFunction · 0.85
_rmtreeFunction · 0.85

Calls 6

listdirMethod · 0.80
getLoggerMethod · 0.80
funcFunction · 0.50
splitMethod · 0.45
sleepMethod · 0.45
warningMethod · 0.45

Tested by

no test coverage detected