有没有办法让 pdb 和 Mac Terminal 很好地发挥作用?

发布于 2024-08-30 16:49:48 字数 271 浏览 5 评论 0原文

调试 django 应用程序时,我使用 pdb 通过 pdb.set_trace() 进行交互式调试。

但是,当我修改文件时,本地 django Web 服务器会重新启动,然后我看不到我在终端中输入的内容,直到我输入 reset

无论如何,这是否会自动发生?这可能真的很烦人,必须取消运行服务器并一直重置并重新启动它。有人告诉我这不会发生在其他操作系统(ubuntu)上,所以有什么办法可以让它不会发生在 Mac 上吗? (我正在使用雪豹)。

When debugging my django apps I use pdb for interactive debugging with pdb.set_trace().

However, when I amend a file the local django webserver restarts and then I cant see what I type in the terminal, until I type reset.

Is there anyway for this to happen automatically? It can be real annoying, having to cancel the runserver and reset and restart it all the time. I'm told it doesn't happen on other OS's (ubuntu) so is there anyway to make it not happen on the Mac? (I'm using Snow Leopard).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧人哭 2024-09-06 16:49:48

好的 - 这对我有用我创建了一个 ~/.pdbrc 并添加

导入操作系统
os.system("stty sane")

现在,每次运行 pdb 时,它都会将线路设置恢复为 sane。

如果我掉到终端,那么我仍然必须手动执行此操作 - 但它解决了必须退出 runserver 并始终重置的问题。

OK - this works for me I created a ~/.pdbrc and added

import os
os.system("stty sane")

Now each time pdb is run it sets the line settings back to sane.

If I fall out to the terminal then I still have to do it manually - but it solves having to quit runserver and reset all the time.

不回头走下去 2024-09-06 16:49:48

在保存对文件的更改之前,尝试 [q]uit pdb。这将防止控制台对您产生影响,但仅限于 pdb.set_trace() 的一次运行。

当您忘记退出 pdb 时,您仍然必须回退到旧的 ^C + reset + ./manage.py runserver。可以让重置不那么烦人的一件事是将重置和运行服务器放在一行上。这样,只需快速 ^Rreset 或向上箭头即可重置。

[ ... ]
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
^C$ reset && ./manage.py runserver

Try to [q]uit pdb before you save changes to a file. This will keep the console from wigging out on you but only for that one run of pdb.set_trace().

You will still have to fallback to the old ^C + reset + ./manage.py runserver when you forget to quit pdb. One thing that can make the reset a little less annoying is to put the reset and runserver onto one line. That way the reset is just a quick ^Rreset or up-arrow away.

[ ... ]
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
^C$ reset && ./manage.py runserver
止于盛夏 2024-09-06 16:49:48

我发现最好的方法是在 pdb 内进行重置,如下所示:

导入操作系统; os.system(“重置”);

The best I've found is doing a reset inside pdb like so:

import os; os.system("reset");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文