From 10d39c83ff5b2a186b2d6b8786375b69c8336419 Mon Sep 17 00:00:00 2001 From: KAAANG <79990647+SAKURA-CAT@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:10:34 +0800 Subject: [PATCH] fix: create (#68) --- swanboard/callback.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/swanboard/callback.py b/swanboard/callback.py index 9c688f4..4884932 100644 --- a/swanboard/callback.py +++ b/swanboard/callback.py @@ -36,6 +36,8 @@ def before_init_experiment( pattern = r"-\d+$" # ---------------------------------- 实验名称校验 ---------------------------------- # 这个循环的目的是如果创建失败则等零点五秒重新生成后缀重新创建,直到创建成功 + # 搜索所有以exp_name开头的实验 + count = Experiment.filter(Experiment.name.startswith(exp_name)).count() while True: try: # 获得数据库实例 @@ -48,15 +50,16 @@ def before_init_experiment( ) break except ExistedError: + count += 1 swanlog.debug(f"Experiment {exp_name} has existed, try another name...") # 以-{数字}结尾 if bool(re.search(pattern, exp_name)): arr = exp_name.split("-") - arr[-1] = str(int(arr[-1]) + 1) + arr[-1] = str(count) exp_name = "-".join(arr) else: - exp_name = f"{exp_name}-1" - time.sleep(0.5) + exp_name = f"{exp_name}-{count}" + time.sleep(0.2) def on_log(self): # 每一次log的时候检查一下数据库中的实验状态