views:

174

answers:

2

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!

A: 

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

Rob Wells
I'm specifically looking for a solution to use in production, so that any slowdown caused by this sort of problem can have limited impact and notify me, instead of slowing down the server until I happen to notice.Perhaps the better solution would be a more general load monitoring/alerting system.
Shimon Rura
@Shimon, such timeouts are typically set on a module basis, e.g. the modules that we've developed for the BBC have timeout options coded into them that can be set via module specific config directives. Let me have a think.
Rob Wells
A: 

The short answer is no, there is no builtin ability within mod_python to have timeouts on individual requests.

Graham Dumpleton