Skip to content

Commit

Permalink
Merge f57580d into b244020
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchall committed Sep 11, 2019
2 parents b244020 + f57580d commit 10ddd5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 2 additions & 3 deletions nrtest/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import os
import logging
import tempfile
import shutil
import json
import datetime

# project imports
from .process import source, execute, monitor
from .utility import color, copy_file_and_path, which
from .utility import color, copy_file_and_path, rmtree, which


class TestFailure(Exception):
Expand Down Expand Up @@ -86,7 +85,7 @@ def _execute(test, app):
copy_file_and_path(fname, tmpdir, test.output_dir)

finally:
shutil.rmtree(tmpdir)
rmtree(tmpdir)

if exitcode == -11:
raise TestFailure('Segmentation fault')
Expand Down
24 changes: 24 additions & 0 deletions nrtest/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ def copy_file_and_path(rel_path, src_dir, dest):
shutil.copy(os.path.join(src_dir, rel_path), dest)


def rmtree(path):
"""Delete an entire directory tree.
This is a wrapper around shutil.rmtree, which handles sporadic
failures on Windows machines by repeating the attempted deletion
with an exponentially increasing timeout (a total timeout of
about 1 second).
"""
# constants taken from CPython's test.support.rmtree()
# i.e. Windows implementation of test.support._waitfor()
timeout = 0.001
max_timeout = 1.0
while timeout < max_timeout:
try:
shutil.rmtree(path)
return
except OSError:
time.sleep(timeout)
timeout *= 2

# final attempt, without exception handling
shutil.rmtree(path)


def which(program, env):
"""Returns absolute path to first occurence of program in the PATH
environment variable (echoing the bash script 'which').
Expand Down

0 comments on commit 10ddd5f

Please sign in to comment.