def runfastcgi(argset=[], **kwargs): import os import newrelic from django.core.servers.fastcgi import FASTCGI_OPTIONS from django.conf import settings from django.core.servers.fastcgi import fastcgi_help options = FASTCGI_OPTIONS.copy() options.update(kwargs) for x in argset: if "=" in x: k, v = x.split('=', 1) else: k, v = x, True options[k.lower()] = v if "help" in options: return fastcgi_help() try: import flup except ImportError, e: print >> sys.stderr, "ERROR: %s" % e print >> sys.stderr, " Unable to load the flup package. In order to run django" print >> sys.stderr, " as a FastCGI application, you will need to get flup from" print >> sys.stderr, " http://www.saddi.com/software/flup/ If you've already" print >> sys.stderr, " installed flup, then make sure you have it in your PYTHONPATH." return False
if options['method'] in ('prefork', 'fork'): wsgi_opts = { 'maxSpare': int(options["maxspare"]), 'minSpare': int(options["minspare"]), 'maxChildren': int(options["maxchildren"]), 'maxRequests': int(options["maxrequests"]), } flup_module += '_fork' elif options['method'] in ('thread', 'threaded'): wsgi_opts = { 'maxSpare': int(options["maxspare"]), 'minSpare': int(options["minspare"]), 'maxThreads': int(options["maxchildren"]), } else: return fastcgi_help("ERROR: Implementation must be one of prefork or thread.") wsgi_opts['debug'] = options['debug'] is not None try: import importlib module = importlib.import_module('.%s' % flup_module, 'flup') WSGIServer = module.WSGIServer except: print "Can't import flup." + flup_module raise return False # Prep up and go from django.core.handlers.wsgi import WSGIHandler