如何确保调试配置之外没有 pdb 调用?
您建议如何消除生产软件上的 pdb 调用? 就我而言,我正在开发一个 django 网站。
我不知道是否应该:
- Monkey patch pdb from settings.py (取决于 DEBUG 布尔值)。
- 为我们的项目制作一个 pdb 包装器,如果 DEBUG = True,则公开 set_trace 或打印基本日志
- Dissallow 在 git hooks 上提交 Brakpoints...(如果您认为这是最好的主意,您会怎么做?)。
What do you suggest to get rid of pdb calls on production software?
In my case, I'm developing a django website.
I don't know if I should:
- Monkey patch pdb from settings.py (dependding on DEBUG boolean).
- Make a pdb wrapper for our project which expose set_trace or print basic log if DEBUG = True
- Dissalow comitting brakpoints on git hooks... (if you think it's the best idea how would you do that?).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第三个。您必须强制执行一些提交规则。例如,在提交之前运行一系列测试等。这样,开发人员就有了一种简单的方法来检查 pdb 中断是否仍然存在。如果有人提交了 set_trace,他就必须为团队的其他成员烤蛋糕。
这在我的公司工作得很好:-)
编辑:您可以将此方法作为 CDD(蛋糕驱动开发)介绍给您的老板
The third one. You have to enforce some commit rules. For example, run a serie of tests before a commit, etc. This way, developpers have a simple way to check if a pdb break remain. If someone commit a set_trace, he has to bake a cake for the rest of the team.
This works fine in my company :-)
edit: you may present this method to your boss as CDD (Cake Driven Developpement)
最好的选择是拥有一个广泛的测试套件,并在投入生产之前运行测试。无关的
pdb
断点将阻止测试通过。如果您做不到这一点,那么选项 2 是最好的:编写一个实用程序来闯入调试器,并使其对设置的状态敏感。不过,您仍然需要解决如何确保人们使用包装器而不是原始
pdb
调用的问题。The best option would be to have an extensive test suite, and to run the tests before pushing to production. Extraneous
pdb
breakpoints will prevent the tests from passing.If you can't do that, then option 2 is the best: write a utility to break into the debugger, and make it sensitive to the state of the settings. You still have to solve the problem of how to be sure people use the wrapper rather than a raw
pdb
call though.理想情况下,您不应该首先包含调试代码。您可以改为使用设置断点并调用主程序进行调试的包装器,以便主程序根本不包含任何实际的
set_trace()
调用。和
示例:
Ideally, You shouldn't be including debugging code in the first place. You can instead use a wrapper that sets breakpoints and invokes the main program for debugging, so that the main program contains no actual
set_trace()
calls at all.and
Example: