简体   繁体   English

为什么不显示 python 回溯消息?

[英]Why are python traceback messages not displayed?

I am trying to convert a python 2 library to python 3. I managed to convert a good part thanks to the python traceback error messages displayed in the terminal.我正在尝试将 python 2转换为 python 3。由于终端中显示的 python 回溯错误消息,我设法转换了一个很好的部分。 But part of this library, which is a web server serving as IDE, does not display error messages making conversion difficult.但是这个库的一部分,它是一个用作 IDE 的 Web 服务器,不显示错误消息,使转换变得困难。

Why are python traceback messages not displayed?为什么不显示 python 回溯消息? Is there a way to display them?有没有办法显示它们?

I found that we could set 'sys.tracebacklimit = 0' to hide the traceback but it didn't have an effect in my case setting it to 1000.我发现我们可以设置 'sys.tracebacklimit = 0' 来隐藏回溯,但在我的情况下将其设置为 1000 没有效果。

As the veteran of a large Python 3 conversion, a few thoughts:作为大Python 3转换的老手,几点感想:

  • The library has a test suite ( python setup.py check ).该库有一个测试套件( python setup.py check )。 That should be your guide as to the correctness of your conversion, not the absence of errors in manual use.这应该是您关于转换正确性的指南,而不是手动使用中没有错误的指南。
  • You don't say what tools you are using.你没有说你在使用什么工具。 I recommend Futurize .我推荐Futurize Do the Stage 1 and Stage 2 conversions (which are mostly automated) to get yourself a codebase that still runs in Python 2, but has been cleaned of things that are guaranteed to break in Python 3. Then you run the tests until you have fixed all the errors and any failures.进行第 1 阶段和第 2 阶段的转换(大部分是自动化的),以获得一个仍然在 Python 2 中运行的代码库,但已经清除了在 Python 3 中肯定会出现的问题。然后运行测试直到修复所有错误和任何失败。
  • This is an 11-year-old old codebase built for Python 2.2.这是一个 11 年前为 Python 2.2 构建的旧代码库。 I recommend getting it running (ie tests passing) under Python 2.7 first rather than going all the way from 2.2.我建议先在 Python 2.7 下运行(即通过测试),而不是从 2.2 开始。 to 3.8.到 3.8。

TLDR: Don't get hung up on trying to surface errors from the server right now. TLDR:不要急于立即从服务器中发现错误。 Use the tests to find the stuff you need to fix.使用测试来查找您需要修复的内容。 Use Futurize.使用未来化。

(I recently gave a "Porting 100,000 lines of Python 2 to Python 3" talk if you're interested.) (如果您有兴趣,我最近发表了“将 100,000 行 Python 2 移植到 Python 3”的演讲。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM