MCPcopy Index your code
hub / github.com/python/cpython / _waitfor

Function _waitfor

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…