Skip to content

Commit

Permalink
fmt error
Browse files Browse the repository at this point in the history
  • Loading branch information
SAKURA-CAT committed Apr 5, 2024
1 parent aa25de1 commit b252943
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions swanlab/cloud/_log_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,36 @@ async def upload(self):
tasks = [x[0].value['upload'](x[1]) for x in self.container]
results = await asyncio.gather(*tasks)
# 检查每一个结果
has_error = False
error_tasks_index = []
for index, result in enumerate(results):
# 如果出现问题
if isinstance(result, UpLoadError):
has_error = True
error_tasks_index.append(index)
continue
elif isinstance(result, Exception):
has_error = True
# 如果出现其他问题,没有办法处理,就直接跳过,但是会有警告
swanlog.error(f"upload logs error: {result}, it might be a swanlab bug, data will be lost!")
continue
# 如果没有错误,清空容器
if not len(error_tasks_index) == 0:
return self.container.clear()
# 如果有错误,只删除错误的部分,等待重新上传
for index in error_tasks_index:
self.container.pop(index)

async def task(self, u: ThreadUtil, *args):
"""
定时任务,定时上传日志信息
:param u: 线程工具类
"""
# 从管道中获取所有的日志信息,存储到self.container中
if self.lock:
return swanlog.debug("upload task still in progressing, passed")
self.container.extend(u.queue.get_all())
# print("线程" + u.name + "获取到的日志信息: ", self.container)
if u.timer.can_run(self.UPLOAD_TIME, len(self.container) == 0):
if self.lock:
return swanlog.debug("upload task still in progressing, passed")
self.lock = True
await self.upload()
# 清除容器内容
self.container.clear()
self.lock = False

async def callback(self, u: ThreadUtil, *args):
Expand Down
2 changes: 1 addition & 1 deletion swanlab/cloud/files_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def wrapper(*args, **kwargs):
result = await func(*args, **kwargs)
return result
except RequestException:
swanlog.error('network error, swanlab will resume uploads when the network improves')
swanlog.warning('network error, swanlab will resume uploads when the network improves')
return NetworkError()
except Exception as e:
return e
Expand Down

0 comments on commit b252943

Please sign in to comment.