Ejemplo n.º 1
0
def robust_rmtree(x):
    retries = 2 if iswindows else 1  # retry on windows to get around the idiotic mandatory file locking
    for i in range(retries):
        try:
            rmtree(x)
            return True
        except EnvironmentError:
            time.sleep(0.1)
    return False
Ejemplo n.º 2
0
def robust_rmtree(x):
    retries = 2 if iswindows else 1  # retry on windows to get around the idiotic mandatory file locking
    for i in range(retries):
        try:
            try:
                rmtree(x)
            except UnicodeDecodeError:
                rmtree(as_bytes(x))
            return True
        except OSError:
            time.sleep(0.1)
    return False
Ejemplo n.º 3
0
def safe_remove(x, is_file=None):
    if is_file is None:
        is_file = os.path.isfile(x)
    try:
        os.remove(x) if is_file else rmtree(x, ignore_errors=True)
    except EnvironmentError:
        pass
Ejemplo n.º 4
0
 def __exit__(self, *a):
     while self.workers:
         p = self.workers.pop()
         if p.poll() is not None:
             continue
         p.terminate()
         if not iswindows and p.poll() is None:
             time.sleep(0.02)
             if p.poll() is None:
                 p.kill()
     del self.workers
     try:
         rmtree(self.tdir)
     except EnvironmentError:
         time.sleep(0.1)
         try:
             rmtree(self.tdir)
         except EnvironmentError:
             pass
     del self.tdir
Ejemplo n.º 5
0
 def tearDown(self):
     rmtree(self.tdir)
     del book_cache_dir.override