使用 WSGI 在守护进程模式下运行 pdb
我正在 Apache 2.2 上使用 mod wsgi 运行 Python 脚本。
是否可以在 wsgi 中使用守护进程模式在 python 脚本中运行 pdb.set_trace() ?
编辑 我想使用守护程序模式而不是嵌入式模式的原因是能够重新加载代码,而不必每次都重新启动 Apache 服务器(嵌入式模式需要)。我希望能够使用代码重新加载,而无需每次重新启动 Apache,并且仍然能够使用 pdb...
I am running a Python script on Apache 2.2 with mod wsgi.
Is it possible to run pdb.set_trace() in a python script using daemon mode in wsgi?
Edit
The reason I want to use daemon mode instead of embedded mode is to have the capability to reload code without having to restart the Apache server every time (which embedded mode requires). I would like to be able to use code reloading without restarting Apache everytime and still be able to use pdb...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的需求,希望能够使用功能极其强大的
pdb
,只要我想调试 Python 服务器代码的某些部分,就可以删除pdb.set_trace()
。是的,Apache 在您无法控制的地方生成 WSGI 应用程序 [1]。但我发现一个很好的折衷方案是
维护您的 Apache
WSGIScriptAlias
并且还可以选择启动您的 Python服务器也在终端中(在本例中进行本地测试,不再通过 Apache 进行测试)
如果有人使用 WSGIScriptAlias 有点像这样......
指向名为
webserver.py
的 Python WSGI 脚本,因此您的
webserver.py
可以有一个简单的开关来在 Apache 使用和开始手动调试。在您的配置文件中保留一个标志,例如在某些
settings.py
中:和
webserver.py
:因此,当您想以交互方式测试您的网络服务器时,只需运行它从终端,
[1] 脚注:有一些非常复杂的方法可以让 Apache 子进程处于您的控制之下,但我认为如果您只想调试 Python 服务器代码,上面的方法要简单得多。如果确实有简单的方法,那么我也很想了解这些。
I had the same need to be able to use the amazingly powerful
pdb
, dropping apdb.set_trace()
wherever I wanted to debug some part of the Python server code.Yes, Apache spawns the WSGI application in a place where it is out of your control [1]. But I found a good compromise is to
maintain your Apache
WSGIScriptAlias
and also give yourself the option of starting your Python server in a terminal as well (testing locally and not through Apache anymore in this case)
So if one uses
WSGIScriptAlias
somewhat like this...pointing to your python WSGI script called
webserver.py
And so your
webserver.py
can have a simple switch to go between being used by Apache and getting started up for debugging manually.Keep a flag in your config file such as, in some
settings.py
:And
webserver.py
:So when you want to test out your webserver interactively, you just run it from a terminal,
[1] Footnote: There are some really complex ways of getting Apache child processes under your control, but I think the above is much simpler if you just want to debug your Python server code. And if there are actually easy ways, then I would love to learn about those too.