Skip to content

Commit

Permalink
update callback
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKURA-CAT committed Apr 6, 2024
1 parent ae06596 commit 6f660e6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion swanlab/cloud/files_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def mock_upload_files(files: List[str]):
# 去重list
files = list(set(files))
files = [os.path.basename(x) for x in files]
print("上传文件信息: ", files)
# print("上传文件信息: ", files)


@async_error_handler
Expand Down
4 changes: 2 additions & 2 deletions swanlab/cloud/start_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def create_thread(self,
callback = ThreadUtil.wrapper_callback(callback, (thread_util, *args)) if callback is not None else None
thread = threading.Thread(target=self._create_loop,
args=(sleep_time, target, (thread_util, *args)),
daemon=True,
name=name)
self.thread_pool[name] = thread
if callback is not None:
Expand Down Expand Up @@ -131,7 +132,7 @@ async def finish(self):
"""
[在主线程中] 结束线程池中的所有线程,并执行所有线程的结束任务
"""
print("线程池准备停止")
# print("线程池准备停止")
# 第一步停止所有非日志上传线程
for name, _ in self.sub_threads:
self.thread_timer[name].cancel()
Expand All @@ -142,6 +143,5 @@ async def finish(self):
await asyncio.gather(*[cb() for cb in self.__callbacks[::-1]])
# 停止日志上传线程的任务
self.thread_timer[self.UPLOAD_THREAD_NAME].cancel()
# TODO 执行日志上传的回调
self.upload_thread.join()
# print("线程池结束")
6 changes: 3 additions & 3 deletions swanlab/data/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ def _before_exit_in_cloud():
exit_in_cloud = True

async def _():
# 关闭线程池
# 展示动画
loading_task = asyncio.create_task(FONT.loading("Waiting for uploading complete", interval=0.5))
# 等待上传线程完成
# 关闭线程池,等待上传线程完成
await run.settings.pool.finish()
loading_task.cancel()
FONT.brush("", length=100, flush=False)
Expand All @@ -342,7 +342,7 @@ def _clean_handler():
# 如果没有错误
if not swanlog.isError:
run.settings.pool and not exit_in_cloud and _before_exit_in_cloud()
swanlog.info("The experiment {} has completed".format(run.settings.exp_name))
swanlog.info("The experiment {} has completed".format(FONT.yellow(run.settings.exp_name)))
# FIXME not a good way to handle this
run._success()
swanlog.setSuccess()
Expand Down
4 changes: 2 additions & 2 deletions swanlab/utils/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import asyncio
import re
from typing import Callable
from typing import Callable, Any

light_colors = [
"#528d59", # 绿色
Expand All @@ -38,7 +38,7 @@
}


def generate_color(number: int = 1) -> str:
def generate_color(number: int = 1) -> tuple[str | Any, str | Any]:
"""输入数字,在设定好顺序的颜色列表中返回十六进制颜色字符串
Returns
Expand Down

0 comments on commit 6f660e6

Please sign in to comment.