如何调试 mod_wsgi/django/apache/wget 超时

发布于 2024-11-04 13:30:41 字数 381 浏览 3 评论 0原文

我有一个通过 django/apache/mod_wsgi 运行的 Web 服务,我正在尝试调试它——在服务器端运行需要很长时间,但使用某些参数时它会超时。我尝试过对 URI 执行直接 wget 操作,并使用 urllib2。我从 wget 收到以下错误:

Read error (Connection timed out) in headers

同时,urllib2 根本不返回任何内容——它似乎在默默地出错。我尝试增加 apache 配置中的 Timeout 指令,但这似乎没有帮助。该服务在不同参数下运行良好。我应该如何调试这个?如果不是apache,超时是从哪里来的?

I have a web service running through django/apache/mod_wsgi that I am trying to debug -- it takes a long time to run server-side, but with certain parameters it just times out. I've tried doing a straight up wget on the URI, and using urllib2. I get the following error from wget:

Read error (Connection timed out) in headers

Meanwhile, urllib2 returns nothing at all -- it seems to be erroring silently. I've tried increasing the Timeout directive in my apache config, but that doesn't seem to help. The service runs fine with different parameters. How should I debug this? Where is the timeout coming from if not apache?

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

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

发布评论

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

评论(1

浮生面具三千个 2024-11-11 13:30:41

问题很可能出在您的服务代码中。在尝试调试 apache 之前,请确保您的服务代码已完成执行并返回到 apache。

我建议您跟踪添加输出语句的服务代码。请务必在代码返回到 mod_wsgi 之前添加输出语句(mod_wsgi 调用的函数的最后一行)。您很可能会看到代码挂在特定位置。也就是说,代码中该位置之前的所有调试语句都将出现,该位置之后的任何输出语句都不会出现。

如果您不想添加调试语句,请尝试使用调试器单步执行代码。

另一种选择是使用 django 开发服务器,看看在没有 apache 的情况下运行时是否会发生超时。但是,由于开发服务器是单线程的,如果您处理的问题是与并发相关的错误,您的代码将不会挂起。

Chances are the problem is in you services code. Make sure your services code completes executing and returns to apache before trying to debug apache.

I would suggest that you trace through the services code adding output statements. Be sure to add a ouput statement just before your code returns to mod_wsgi (the last line of the function that mod_wsgi calls.) Chances are what you will see is the code hanging in a particular spot. That is all the debug statements prior to that spot in the code will appear, none of the output statements after that spot will appear.

If you don't want to add debug statement try using a debugger to step through the code.

Another option is to use the django development server and see if the timeout occurs when running without apache. However, since the development server is single threaded your code won't hang if the problem your dealing with is a concurrency related bug.

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