Skip to content

Commit

Permalink
fix: create (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKURA-CAT authored Nov 24, 2024
1 parent 3a54bf1 commit 10d39c8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions swanboard/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# 获得数据库实例
Expand All @@ -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的时候检查一下数据库中的实验状态
Expand Down

0 comments on commit 10d39c8

Please sign in to comment.