I forgot to mention you can test the wsgi app with the following: - http://localhost/myapp?sleep=5 will run to completion - http://localhost/myapp?sleep=30 will run for 10 seconds and then timeout
On Jun 27, 7:19 pm, marwan <[email protected]> wrote: > Hi all, > I want to put a limit on the execution time of page requests, to > protect against some pages that might run large or inefficient > queries. I've looked around the docs and the Configuration Directives > but couldn't find out how to do it that way. I'm running the following > stack: > mod_wsgi 2.8 Apache/2.2.14 Ubuntu 10.04 Python 2.6.5 Linux > > my httpd.conf is as follows: > ServerName 127.0.0.1 > SetEnv no-gzip > WSGIDaemonProcess myapp processes=1 threads=1 python-path=/var/www/ > WSGIProcessGroup myapp > WSGIScriptAlias /myapp /var/www/myapp.wsgi > > I have implemented the following solution, and it seems to work but I > wanted to get peoples feedback on whether or not this is the best way > to do this: > > this is the contents of /var/www/myapp.wsgi: > > import time, os, threading, signal, Queue, cgi > > class TimeoutMonitor(threading.Thread): > def __init__(self, timeoutQ, timeout): > threading.Thread.__init__(self) > self.timeoutQ = timeoutQ > self.timeout = timeout > > def run(self): > try: > self.timeoutQ.get(timeout=self.timeout) > except Queue.Empty: > os.kill(os.getpid(), signal.SIGKILL) > > def application(environ, start_response): > parameters = cgi.parse_qs(environ.get('QUERY_STRING', '')) > start_response('200 OK', [('Content-type', 'text/plain')]) > timeoutQ = Queue.Queue() > TimeoutMonitor(timeoutQ, timeout=10).start() > > for i in range(int(parameters['sleep'][0])): > time.sleep(1) > yield str(i) + '\n' > yield 'done' > timeoutQ.put('done') > > I have a few questions: > - Is there another simpler or better way of doing this? maybe through > some configuration parameter? > - In general is it alright to spawn threads in modwsgi (in daemon > mode)? > - Is it better to send a SIGKILL, SIGTERM, or SIGINT signal? -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
