def safe_rmdir(path, timeout=10):
 assert os.path.isdir(path), ('Invalid directory to remove %s' % path)
 step = int((timeout / 10))
 start_time = time.time()
 success = False
 attempts = 0
 while (int((time.time() - start_time)) < timeout):
  attempts += 1
  try:
   shutil.rmtree(path)
   success = True
   break
  except OSError as err_info:
   if (err_info.errno != 39):
    raise
   time.sleep(step)
 if (not success):
  raise OSError(39, ('Could not delete directory %s after %d s and %d attempts.' % (path, timeout, attempts)))

def safe_rmdir ( path , timeout = 10 ) : assert os . path . isdir ( path ) , ( 'Invalid directory to remove %s' % path ) step = int ( ( timeout / 10 ) ) start_time = time . time ( ) success = False attempts = 0 while ( int ( ( time . time ( ) - start_time ) ) < timeout ) : attempts += 1 try : shutil . rmtree ( path ) success = True break except OSError as err_info : if ( err_info . errno != 39 ) : raise time . sleep ( step ) if ( not success ) : raise OSError ( 39 , ( 'Could not delete directory %s after %d s and %d attempts.' % ( path , timeout , attempts ) ) )
try to remove a directory safely .