Example #1
0
    def __init__(self, application, environ=None,
                 multithreaded=True, multiprocess=False,
                 bindAddress=None, multiplexed=False, **kw):
        """
        environ, if present, must be a dictionary-like object. Its
        contents will be copied into application's environ. Useful
        for passing application-specific variables.

        bindAddress, if present, must either be a string or a 2-tuple. If
        present, run() will open its own listening socket. You would use
        this if you wanted to run your application as an 'external' FastCGI
        app. (i.e. the webserver would no longer be responsible for starting
        your app) If a string, it will be interpreted as a filename and a UNIX
        socket will be opened. If a tuple, the first element, a string,
        is the interface name/IP to bind to, and the second element (an int)
        is the port number.
        """
        BaseFCGIServer.__init__(self, application,
                                environ=environ,
                                multithreaded=multithreaded,
                                multiprocess=multiprocess,
                                bindAddress=bindAddress,
                                multiplexed=multiplexed)
        for key in ('jobClass', 'jobArgs'):
            if kw.has_key(key):
                del kw[key]
        ThreadedServer.__init__(self, jobClass=self._connectionClass,
                                jobArgs=(self,), **kw)
Example #2
0
    def __init__(self, application, environ=None,
                 bindAddress=None, multiplexed=False, **kw):
        """
        environ, if present, must be a dictionary-like object. Its
        contents will be copied into application's environ. Useful
        for passing application-specific variables.

        bindAddress, if present, must either be a string or a 2-tuple. If
        present, run() will open its own listening socket. You would use
        this if you wanted to run your application as an 'external' FastCGI
        app. (i.e. the webserver would no longer be responsible for starting
        your app) If a string, it will be interpreted as a filename and a UNIX
        socket will be opened. If a tuple, the first element, a string,
        is the interface name/IP to bind to, and the second element (an int)
        is the port number.
        """
        BaseFCGIServer.__init__(self, application,
                                environ=environ,
                                multithreaded=False,
                                multiprocess=True,
                                bindAddress=bindAddress,
                                multiplexed=multiplexed)
        for key in ('multithreaded', 'multiprocess', 'jobClass', 'jobArgs'):
            if kw.has_key(key):
                del kw[key]
        PreforkServer.__init__(self, jobClass=self._connectionClass,
                               jobArgs=(self,), **kw)

        try:
            import resource
            # Attempt to glean the maximum number of connections
            # from the OS.
            maxProcs = resource.getrlimit(resource.RLIMIT_NPROC)[0]
            maxConns = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
            maxConns = min(maxConns, maxProcs)
        except ImportError:
            maxConns = 100 # Just some made up number.
        maxReqs = maxConns
        self.capability = {
            FCGI_MAX_CONNS: maxConns,
            FCGI_MAX_REQS: maxReqs,
            FCGI_MPXS_CONNS: 0
            }