Loading csst_common/utils/_retry.py +17 −10 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ Modified-History: 2023-12-20, Bo Zhang, add retry """ import traceback def retry(func, *args, **kwargs): if "n_try" in kwargs.keys(): Loading @@ -15,11 +16,7 @@ def retry(func, *args, **kwargs): else: n_try = 5 # is DFS? try: assert func.__self__.__class__.__module__.startswith("csst_dfs_api"), func is_dfs = True except BaseException: is_dfs = False is_dfs = func.__self__.__class__.__module__.startswith("csst_dfs_client") # start trials for attempt in range(n_try): print(f"Trial #{attempt}: call {func}") Loading @@ -28,9 +25,19 @@ def retry(func, *args, **kwargs): if is_dfs: assert res["code"] == 0, res return res except BaseException as e: print(f"Error occurs: {e.__repr__()}") print(f" - func: {func}") print(f" - args: {args}") print(f" - kwargs: {kwargs}") except Exception as e: # print error messages print(f"Error occurs in trial {attempt + 1}/{n_try}:") print(f" - Error type: {type(e).__name__}") print(f" - Error message: {str(e)}") print(f" - Function: {func}") print(f" - Args: {args}") print(f" - Kwargs: {kwargs}") # 打印完整的堆栈跟踪 print(" - Stack trace:") traceback.print_exc() if attempt == n_try - 1: print(f"All {n_try} attempts failed. Reraising exception...") raise raise RuntimeError(f"All {n_try} attempts failed.") Loading
csst_common/utils/_retry.py +17 −10 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ Modified-History: 2023-12-20, Bo Zhang, add retry """ import traceback def retry(func, *args, **kwargs): if "n_try" in kwargs.keys(): Loading @@ -15,11 +16,7 @@ def retry(func, *args, **kwargs): else: n_try = 5 # is DFS? try: assert func.__self__.__class__.__module__.startswith("csst_dfs_api"), func is_dfs = True except BaseException: is_dfs = False is_dfs = func.__self__.__class__.__module__.startswith("csst_dfs_client") # start trials for attempt in range(n_try): print(f"Trial #{attempt}: call {func}") Loading @@ -28,9 +25,19 @@ def retry(func, *args, **kwargs): if is_dfs: assert res["code"] == 0, res return res except BaseException as e: print(f"Error occurs: {e.__repr__()}") print(f" - func: {func}") print(f" - args: {args}") print(f" - kwargs: {kwargs}") except Exception as e: # print error messages print(f"Error occurs in trial {attempt + 1}/{n_try}:") print(f" - Error type: {type(e).__name__}") print(f" - Error message: {str(e)}") print(f" - Function: {func}") print(f" - Args: {args}") print(f" - Kwargs: {kwargs}") # 打印完整的堆栈跟踪 print(" - Stack trace:") traceback.print_exc() if attempt == n_try - 1: print(f"All {n_try} attempts failed. Reraising exception...") raise raise RuntimeError(f"All {n_try} attempts failed.")