def _retry(func, *args, **kwargs): for _ in range(300): try: func(*args, **kwargs) break except sh.ErrorReturnCode: sleep(0.1) else: raise