如何从 ipynb 错误回溯 ['stack'] 中获取人类可读的调用堆栈?

问题描述 投票:0回答:1

我在笔记本中遇到了一个错误,它没有显示完整的调用堆栈,而是一个截断的堆栈,只有最后几个调用,顶部打印了以下消息:

Output exceeds the size limit. Open the full output data *in a text editor*

链接到文本文件,如:

{
    "name": "TypeError",
    "message": "default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'anndata._core.anndata.AnnData'>",
    "stack": "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)\nFile \u001b[0;32m/usr/local/python/lib/python3.8/site-packages/torch/utils/data/_utils/collate.py:128\u001b[0m, in \u001b[0;36mcollate\u001b[0;34m(batch, collate_fn_map)\u001b[0m\n\u001b[1;32m    127\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 128\u001b[0m     \u001b[39mreturn\u001b[39;00m elem_type({key: collate([d[key] \u001b[39mfor\u001b[39;00m d \u001b[39min\u001b[39;00m batch], collate_fn_map\u001b[39m=\u001b[39mcollate_fn_map) \u001b[39mfor\u001b[39;00m key \u001b[39min\u001b[39;00m elem})\n\u001b[1;32m    129\u001b[0m \u001

问题是

['stack']
不是人类可读的值。

如何以人类可读的形式从中获得完整的调用堆栈?

python exception jupyter stack-trace
1个回答
0
投票

试试这个:

with open(filename) as f:
    data = json.read(f)
print(data["stack"])
© www.soinside.com 2019 - 2024. All rights reserved.