Skip to content

Commit

Permalink
修复云端版和本地版bug报错输出信息不准确的问题 (#640)
Browse files Browse the repository at this point in the history
* change print error format by KANG

* update error print

* update version

---------

Co-authored-by: ZeYi Lin <[email protected]>
Co-authored-by: KAAANG <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2024
1 parent 9ae1a1b commit 39b7b0f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
11 changes: 3 additions & 8 deletions swanlab/data/callback_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,14 @@ def _clean_handler(self):

def _except_handler(self, tp, val, tb):
if self.exiting:
# FIXME not a good way to fix '\n' problem
print("")
swanlog.error("Aborted uploading by user")
sys.exit(1)
self._error_print(tp)
# 结束运行
get_run().finish(SwanLabRunState.CRASHED, error=self._traceback_error(tb))
get_run().finish(SwanLabRunState.CRASHED, error=self._traceback_error(tb, tp(val)))
if tp != KeyboardInterrupt:
raise tp(val)
print(self._traceback_error(tb, tp(val)), file=sys.stderr)

def __str__(self):
return "SwanLabCloudRunCallback"
Expand Down Expand Up @@ -244,11 +243,7 @@ def on_column_create(self, column_info: ColumnInfo):
error = None
if column_info.error is not None:
error = {"data_class": column_info.error.got, "excepted": column_info.error.expected}
column = ColumnModel(
key=column_info.key,
column_type=column_info.chart.value.column_type,
error=error
)
column = ColumnModel(key=column_info.key, column_type=column_info.chart.value.column_type, error=error)
self.pool.queue.put((UploadType.COLUMN, [column]))

def on_metric_create(self, metric_info: MetricInfo):
Expand Down
10 changes: 6 additions & 4 deletions swanlab/data/callback_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import traceback
import json
import os
import sys


class LocalRunCallback(SwanLabRunCallback):
Expand All @@ -26,14 +27,15 @@ def __init__(self):
super(LocalRunCallback, self).__init__()

@staticmethod
def _traceback_error(tb):
def _traceback_error(tb, val):
"""
获取traceback信息
"""
trace_list = traceback.format_tb(tb)
html = ""
for line in trace_list:
html += line + "\n"
html += line
html += str(val)
return html

@staticmethod
Expand Down Expand Up @@ -97,9 +99,9 @@ def _except_handler(self, tp, val, tb):
"""
self._error_print(tp)
# 结束运行
get_run().finish(SwanLabRunState.CRASHED, error=self._traceback_error(tb))
get_run().finish(SwanLabRunState.CRASHED, error=self._traceback_error(tb, tp(val)))
if tp != KeyboardInterrupt:
raise tp(val)
print(self._traceback_error(tb, tp(val)), file=sys.stderr)

def _clean_handler(self):
run = get_run()
Expand Down
16 changes: 10 additions & 6 deletions swanlab/data/modules/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
if TYPE_CHECKING:
# noinspection PyPackageRequirements
import matplotlib as _matplotlib # type: ignore

# noinspection PyPackageRequirements
import numpy as _numpy # type: ignore

# noinspection PyPackageRequirements
import torch as _torch # type: ignore

# noinspection PyPackageRequirements
from PIL.Image import Image as _PILImage # type: ignore

Expand Down Expand Up @@ -55,12 +58,12 @@ class Image(MediaType):
ACCEPT_FORMAT = ["png", "jpg", "jpeg", "bmp"]

def __init__(
self,
data_or_path: "ImageDataOrPathType",
mode: str = None,
caption: str = None,
file_type: str = None,
size: Union[int, list, tuple] = None,
self,
data_or_path: "ImageDataOrPathType",
mode: str = None,
caption: str = None,
file_type: str = None,
size: Union[int, list, tuple] = None,
):
"""Image class constructor
Expand Down Expand Up @@ -96,6 +99,7 @@ def __init__(
try:
# noinspection PyPackageRequirements
from PIL import Image as PILImage

# noinspection PyPackageRequirements
import numpy as np
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion swanlab/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swanlab",
"version": "0.3.12",
"version": "0.3.13",
"description": "",
"python": "true"
}

0 comments on commit 39b7b0f

Please sign in to comment.