【发布时间】:2023-03-27 15:26:02
【问题描述】:
我想使用pdb 在交互模式下调试为 Sphinx 编写的扩展,该扩展非常适合简单的脚本。当我执行sphinx-build -M html . _build 时,我得到一个ValueError。所以为了调试它,我写道:
ipython3 $(which sphinx-build) --pdb -- -M html . _build
不幸的是,我没有得到完整的回溯,只有来自主脚本sphinx-build:
$ ipython3 $(which sphinx-build) --pdb -- -M html . _build
Running Sphinx v3.1.2
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/sphinx/config.py", line 319,
in eval_config_file
execfile_(filename, namespace)
File "/usr/local/lib/python3.6/dist-packages/sphinx/util/pycompat.py", line 88,
in execfile_
exec(code, _globals)
File "/home/canard/test-sphinx/conf.py", line 17, in <module>
raise ValueError()
ValueError
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
/usr/local/bin/sphinx-build in <module>()
9 if __name__ == '__main__':
10 sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
---> 11 sys.exit(main())
SystemExit: 2
> /usr/local/bin/sphinx-build(11)<module>()
7 from sphinx.cmd.build import main
8
9 if __name__ == '__main__':
10 sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
---> 11 sys.exit(main())
ipdb>
如何查看完整的回溯?
我试图通过将raise ValueError() 添加到conf.py 来简化案例。所以要重现只需使用sphinx-quickstart 创建一个新的狮身人面像项目,修改conf.py 并添加异常。使用此设置,您会遇到同样的问题。调试器停在sys.exit(main())
【问题讨论】:
标签: python debugging exception pdb