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)
def __init__( self, application, scriptName="", environ=None, multithreaded=True, multiprocess=False, bindAddress=("localhost", 8009), allowedServers=None, loggingLevel=logging.INFO, **kw ): """ scriptName is the initial portion of the URL path that "belongs" to your application. It is used to determine PATH_INFO (which doesn't seem to be passed in). An empty scriptName means your application is mounted at the root of your virtual host. environ, which must be a dictionary, can contain any additional environment variables you want to pass to your application. bindAddress is the address to bind to, which must be a tuple of length 2. The first element is a string, which is the host name or IPv4 address of a local interface. The 2nd element is the port number. allowedServers must be None or a list of strings representing the IPv4 addresses of servers allowed to connect. None means accept connections from anywhere. loggingLevel sets the logging level of the module-level logger. """ BaseAJPServer.__init__( self, application, scriptName=scriptName, environ=environ, multithreaded=multithreaded, multiprocess=multiprocess, bindAddress=bindAddress, allowedServers=allowedServers, loggingLevel=loggingLevel, ) for key in ("jobClass", "jobArgs"): if kw.has_key(key): del kw[key] ThreadedServer.__init__(self, jobClass=Connection, jobArgs=(self,), **kw)
def run(self): """ The main loop. Exits on SIGHUP, SIGINT, SIGTERM. Returns True if SIGHUP was received, False otherwise. """ self._web_server_addrs = os.environ.get('FCGI_WEB_SERVER_ADDRS') if self._web_server_addrs is not None: self._web_server_addrs = map(lambda x: x.strip(), self._web_server_addrs.split(',')) sock = self._setupSocket() ret = ThreadedServer.run(self, sock) self._cleanupSocket(sock) return ret
#!/usr/bin/python3 import sys #import signal from PyQt4.QtCore import QCoreApplication from threadedserver import ThreadedServer def exit_handler(*args): print('Exiting!') sys.exit(0) if __name__ == '__main__': app = QCoreApplication(sys.argv) server = ThreadedServer(listen_port=32000) #signal.signal(signal.SIGINT, exit_handler) sys.exit(app.exec_())