如何配置 Apache2/mod_python/Django 在 N 秒后中止请求处理?
我最近花了很长时间调试一些东西,结果发现我自己的代码中存在无限循环错误。因为我不能保证我永远不会再犯这种错误,所以我如何配置我的 Web 服务器来终止任何仍在等待我的 python 应用程序返回响应超过 N 秒的 apache2 子进程?
在这种情况下,我什至没有注意到这个错误,直到网站开始感觉缓慢,此时一个 apache2 进程已经在无限循环中运行了几个小时。如果有一个超时(即使是很长的超时,例如 10 分钟)可以捕获此问题并向我发送电子邮件,我就会更快地知道该问题,并且它不会影响那么多用户的网站性能。
谷歌搜索,我在 mod_wsgi 配置中发现了一些类似的建议,但如果有一种方法可以在我当前的设置下做到这一点,我会更喜欢这样做。谢谢!
I recently spent a long while debugging something that turned out to be an infinite loop bug in my own code. Since I can't guarantee I'll never make that sort of mistake again, how can I configure my web server to terminate any apache2 subprocess that remains waiting for my python app to return a response for over N seconds?
In this case, I didn't even notice the bug until the site started feeling slow, at which point one apache2 process had been running inside an infinite loop for hours. If there were a timeout (even a long one, like 10min) that could have caught this and emailed me, I'd have known about the problem sooner, and it wouldn't have impacted site performance for as many users.
Googling, I've found some suggestions of similar things in a mod_wsgi configuration, but if there's a way to do this under my current setup I'd prefer that. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是否定的,mod_python 中没有内置功能来对单个请求设置超时。
The short answer is no, there is no builtin ability within mod_python to have timeouts on individual requests.
嗯。
我想知道您是否可以使用 mod_cgi 来运行您的 Python 脚本进行开发。然后回到mod_python进行部署。
然后,您可以使用 Apache 核心 TimeOut 指令来限制 Apache 等待 mod_cgi 响应的时间。注意 Apache 2.2,即 TimeOut 指令的此扩展仅随 2.2 版本一起提供。
华泰
Hmmm.
I wonder if you can use mod_cgi to run your Python script for development. And then go back to mod_python for deployment.
Then you can use the Apache core TimeOut directive to limit how long Apache waits for the mod_cgi response. N.B. Apache 2.2 that is, this extension to the TimeOut directive only came with the 2.2 release.
HTH