parent
6061476d8e
commit
954b567b9b
19 changed files with 77 additions and 84 deletions
@ -1,9 +0,0 @@ |
|||||||
# remove all keys that end in DEPRECATED |
|
||||||
def strip_deprecated_keys(d): |
|
||||||
for k in list(d.keys()): |
|
||||||
if isinstance(k, str): |
|
||||||
if k.endswith('DEPRECATED'): |
|
||||||
d.pop(k) |
|
||||||
elif isinstance(d[k], dict): |
|
||||||
strip_deprecated_keys(d[k]) |
|
||||||
return d |
|
||||||
@ -1,30 +0,0 @@ |
|||||||
import time |
|
||||||
import functools |
|
||||||
|
|
||||||
from openpilot.common.swaglog import cloudlog |
|
||||||
|
|
||||||
|
|
||||||
def retry(attempts=3, delay=1.0, ignore_failure=False): |
|
||||||
def decorator(func): |
|
||||||
@functools.wraps(func) |
|
||||||
def wrapper(*args, **kwargs): |
|
||||||
for _ in range(attempts): |
|
||||||
try: |
|
||||||
return func(*args, **kwargs) |
|
||||||
except Exception: |
|
||||||
cloudlog.exception(f"{func.__name__} failed, trying again") |
|
||||||
time.sleep(delay) |
|
||||||
|
|
||||||
if ignore_failure: |
|
||||||
cloudlog.error(f"{func.__name__} failed after retry") |
|
||||||
else: |
|
||||||
raise Exception(f"{func.__name__} failed after retry") |
|
||||||
return wrapper |
|
||||||
return decorator |
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": |
|
||||||
@retry(attempts=10) |
|
||||||
def abc(): |
|
||||||
raise ValueError("abc failed :(") |
|
||||||
abc() |
|
||||||
@ -1,28 +0,0 @@ |
|||||||
import subprocess |
|
||||||
from contextlib import contextmanager |
|
||||||
from subprocess import Popen, PIPE, TimeoutExpired |
|
||||||
|
|
||||||
|
|
||||||
def run_cmd(cmd: list[str], cwd=None, env=None) -> str: |
|
||||||
return subprocess.check_output(cmd, encoding='utf8', cwd=cwd, env=env).strip() |
|
||||||
|
|
||||||
|
|
||||||
def run_cmd_default(cmd: list[str], default: str = "", cwd=None, env=None) -> str: |
|
||||||
try: |
|
||||||
return run_cmd(cmd, cwd=cwd, env=env) |
|
||||||
except subprocess.CalledProcessError: |
|
||||||
return default |
|
||||||
|
|
||||||
|
|
||||||
@contextmanager |
|
||||||
def managed_proc(cmd: list[str], env: dict[str, str]): |
|
||||||
proc = Popen(cmd, env=env, stdout=PIPE, stderr=PIPE) |
|
||||||
try: |
|
||||||
yield proc |
|
||||||
finally: |
|
||||||
if proc.poll() is None: |
|
||||||
proc.terminate() |
|
||||||
try: |
|
||||||
proc.wait(timeout=5) |
|
||||||
except TimeoutExpired: |
|
||||||
proc.kill() |
|
||||||
Loading…
Reference in new issue