(func, pathname, waitall=False)
| 377 | |
| 378 | if 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) |
no test coverage detected
searching dependent graphs…