Robert Brewer  committed 353ae45

Added CGI adapter to and cherryd. See #894.

  • Participants
  • Parent commits 8b2d2cf

Comments (0)

Files changed (2)

File cherrypy/cherryd

 from cherrypy import Application
 def start(configfiles=None, daemonize=False, environment=None,
-          fastcgi=False, scgi=False, pidfile=None, imports=None):
+          fastcgi=False, scgi=False, pidfile=None, imports=None,
+          cgi=False):
     """Subscribe all engine plugins and start the engine."""
     sys.path = [''] + sys.path
     for i in imports or []:
     if hasattr(engine, "console_control_handler"):
-    if fastcgi and scgi:
-        # fastcgi and scgi aren't allowed together.
-        cherrypy.log.error("fastcgi and scgi aren't allowed together.", 'ENGINE')
+    if (fastcgi and (scgi or cgi)) or (scgi and cgi):
+        cherrypy.log.error("You may only specify one of the cgi, fastcgi, and "
+                           "scgi options.", 'ENGINE')
-    elif fastcgi or scgi:
-        # Turn off autoreload when using fastcgi or scgi.
+    elif fastcgi or scgi or cgi:
+        # Turn off autoreload when using *cgi.
         cherrypy.config.update({'engine.autoreload_on': False})
         # Turn off the default HTTP server (which is subscribed by default).
         if fastcgi:
             f = servers.FlupFCGIServer(application=cherrypy.tree,
-        else:
+        elif scgi:
             f = servers.FlupSCGIServer(application=cherrypy.tree,
+        else:
+            f = servers.FlupCGIServer(application=cherrypy.tree,
+                                      bindAddress=addr)
         s = servers.ServerAdapter(engine, httpserver=f, bind_addr=addr)
                  help="start a fastcgi server instead of the default HTTP server")
     p.add_option('-s', action="store_true", dest='scgi',
                  help="start a scgi server instead of the default HTTP server")
+    p.add_option('-x', action="store_true", dest='cgi',
+                 help="start a cgi server instead of the default HTTP server")
     p.add_option('-i', '--import', action="append", dest='imports',
                  help="specify modules to import")
     p.add_option('-p', '--pidfile', dest='pidfile', default=None,
             sys.path.insert(0, p)
     start(options.config, options.daemonize,
-          options.environment, options.fastcgi, options.scgi, options.pidfile,
-          options.imports)
+          options.environment, options.fastcgi, options.scgi,
+          options.pidfile, options.imports, options.cgi)

File cherrypy/process/

+class FlupCGIServer(object):
+    """Adapter for a flup.server.cgi.WSGIServer."""
+    def __init__(self, *args, **kwargs):
+        self.args = args
+        self.kwargs = kwargs
+        self.ready = False
+    def start(self):
+        """Start the CGI server."""
+        # We have to instantiate the server class here because its __init__
+        # starts a threadpool. If we do it too early, daemonize won't work.
+        from flup.server.cgi import WSGIServer
+        self.cgiserver = WSGIServer(*self.args, **self.kwargs)
+        self.ready = True
+    def stop(self):
+        """Stop the HTTP server."""
+        self.ready = False
 class FlupFCGIServer(object):
     """Adapter for a flup.server.fcgi.WSGIServer."""