Move exception_records related methods to errors.py
This commit is contained in:
parent
959404e0e2
commit
86b99b1e98
|
@ -6,6 +6,21 @@ import traceback
|
||||||
exception_records = []
|
exception_records = []
|
||||||
|
|
||||||
|
|
||||||
|
def format_traceback(tb):
|
||||||
|
return [[f"{x.filename}, line {x.lineno}, {x.name}", x.line] for x in traceback.extract_tb(tb)]
|
||||||
|
|
||||||
|
|
||||||
|
def format_exception(e, tb):
|
||||||
|
return {"exception": str(e), "traceback": format_traceback(tb)}
|
||||||
|
|
||||||
|
|
||||||
|
def get_exceptions():
|
||||||
|
try:
|
||||||
|
return list(reversed(exception_records))
|
||||||
|
except Exception as e:
|
||||||
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
def record_exception():
|
def record_exception():
|
||||||
_, e, tb = sys.exc_info()
|
_, e, tb = sys.exc_info()
|
||||||
if e is None:
|
if e is None:
|
||||||
|
@ -14,8 +29,7 @@ def record_exception():
|
||||||
if exception_records and exception_records[-1] == e:
|
if exception_records and exception_records[-1] == e:
|
||||||
return
|
return
|
||||||
|
|
||||||
from modules import sysinfo
|
exception_records.append(format_exception(e, tb))
|
||||||
exception_records.append(sysinfo.format_exception(e, tb))
|
|
||||||
|
|
||||||
if len(exception_records) > 5:
|
if len(exception_records) > 5:
|
||||||
exception_records.pop(0)
|
exception_records.pop(0)
|
||||||
|
|
|
@ -85,7 +85,7 @@ def get_dict():
|
||||||
"Checksum": checksum_token,
|
"Checksum": checksum_token,
|
||||||
"Commandline": sys.argv,
|
"Commandline": sys.argv,
|
||||||
"Torch env info": get_torch_sysinfo(),
|
"Torch env info": get_torch_sysinfo(),
|
||||||
"Exceptions": get_exceptions(),
|
"Exceptions": errors.get_exceptions(),
|
||||||
"CPU": {
|
"CPU": {
|
||||||
"model": platform.processor(),
|
"model": platform.processor(),
|
||||||
"count logical": psutil.cpu_count(logical=True),
|
"count logical": psutil.cpu_count(logical=True),
|
||||||
|
@ -105,21 +105,6 @@ def get_dict():
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def format_traceback(tb):
|
|
||||||
return [[f"{x.filename}, line {x.lineno}, {x.name}", x.line] for x in traceback.extract_tb(tb)]
|
|
||||||
|
|
||||||
|
|
||||||
def format_exception(e, tb):
|
|
||||||
return {"exception": str(e), "traceback": format_traceback(tb)}
|
|
||||||
|
|
||||||
|
|
||||||
def get_exceptions():
|
|
||||||
try:
|
|
||||||
return list(reversed(errors.exception_records))
|
|
||||||
except Exception as e:
|
|
||||||
return str(e)
|
|
||||||
|
|
||||||
|
|
||||||
def get_environment():
|
def get_environment():
|
||||||
return {k: os.environ[k] for k in sorted(os.environ) if k in environment_whitelist}
|
return {k: os.environ[k] for k in sorted(os.environ) if k in environment_whitelist}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue