Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1824

Show
Ignore:
Timestamp:
11/11/07 13:47:09
Author:
fumanchu
Message:

Trunk fix for #752 (Return cherrypy.server to a single-server model):

  1. Change restsrv.servers.ServerManager? (multiple httpservers) to ServerAdapter? (one httpserver).
  2. cherrypy.server is now a subclass of ServerAdapter?, and is subscribed by default.
  3. Made several plugin methods idempotent that weren't before.
  4. Added names to win32 bus state events. Also fixed a buglet in win32 block().
  5. Added repr to wspbus.states.State objects.
  6. Did not change any callers of cherrypy.server other than what was necessary, to help prove the fixes work without breaking compatibility. Future changesets will be used to modify docs and tutorials n such.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/__init__.py

    r1793 r1824  
    213213engine.autoreload = restsrv.plugins.Autoreloader(engine) 
    214214engine.autoreload.subscribe() 
     215 
    215216restsrv.plugins.ThreadManager(engine).subscribe() 
     217 
     218signal_handler = restsrv.plugins.SignalHandler(engine) 
    216219 
    217220from cherrypy import _cpserver 
    218221server = _cpserver.Server() 
     222server.subscribe() 
    219223 
    220224 
     
    240244    tree.mount(root, script_name, config) 
    241245     
    242     engine.subscribe('start', server.quickstart) 
    243     restsrv.plugins.SignalHandler(engine).subscribe() 
     246    signal_handler.subscribe() 
    244247    engine.start() 
    245248    engine.block() 
     
    386389# Using an access file makes CP about 10% slower. Leave off by default. 
    387390log.access_file = '' 
    388 engine.subscribe('log', lambda msg: log.error(msg, 'ENGINE')) 
     391 
     392def _buslog(msg): 
     393    log.error(msg, 'ENGINE') 
     394engine.subscribe('log', _buslog) 
    389395 
    390396#                       Helper functions for CP apps                       # 
  • trunk/cherrypy/_cpmodpy.py

    r1787 r1824  
    9090                            }) 
    9191     
     92    cherrypy.server.unsubscribe() 
    9293    cherrypy.engine.start() 
    9394     
  • trunk/cherrypy/_cpserver.py

    r1767 r1824  
    55import cherrypy 
    66from cherrypy.lib import attributes 
     7 
     8# We import * because we want to export check_port 
     9# et al as attributes of this module. 
    710from cherrypy.restsrv.servers import * 
    811 
    912 
    10 class Server(object): 
    11     """Manager for a set of HTTP servers
     13class Server(ServerAdapter): 
     14    """An adapter for an HTTP server
    1215     
    13     This is both a container and controller for "HTTP server" objects, 
    14     which are kept in Server.httpservers, a dictionary of the form: 
    15     {httpserver: bind_addr} where 'bind_addr' is usually a (host, port) 
    16     tuple. 
    17      
    18     Most often, you will only be starting a single HTTP server. In this 
    19     common case, you can set attributes (like socket_host and socket_port) 
     16    You can set attributes (like socket_host and socket_port) 
    2017    on *this* object (which is probably cherrypy.server), and call 
    2118    quickstart. For example: 
     
    2926        s = MyCustomWSGIServer(wsgiapp, port=8080) 
    3027        cherrypy.server.quickstart(s) 
    31      
    32     But if you need to start more than one HTTP server (to serve on multiple 
    33     ports, or protocols, etc.), you can manually register each one and then 
    34     control them all: 
    35      
    36         s1 = MyWSGIServer(host='0.0.0.0', port=80) 
    37         s2 = another.HTTPServer(host='127.0.0.1', SSL=True) 
    38         cherrypy.server.httpservers = {s1: ('0.0.0.0', 80), 
    39                                        s2: ('127.0.0.1', 443)} 
    40         # Note we do not use quickstart when we define our own httpservers 
    41         cherrypy.server.start() 
    42      
    43     Whether you use quickstart(), or define your own httpserver entries and 
    44     use start(), you'll find that the start, wait, restart, and stop methods 
    45     work the same way, controlling all registered httpserver objects at once. 
    4628    """ 
    4729     
     
    8163     
    8264    def __init__(self): 
    83         self.mgr = ServerManager(cherrypy.engine) 
    84      
    85     def _get_httpservers(self): 
    86         return self.mgr.httpservers 
    87     def _set_httpservers(self, value): 
    88         self.mgr.httpservers = value 
    89     httpservers = property(_get_httpservers, _set_httpservers) 
     65        ServerAdapter.__init__(self, cherrypy.engine) 
    9066     
    9167    def quickstart(self, server=None): 
     
    9672        and attributes of self. 
    9773        """ 
    98         httpserver, bind_addr = self.httpserver_from_self(server) 
    99         self.mgr.httpservers[httpserver] = bind_addr 
    100         self.mgr.start() 
    101         cherrypy.engine.subscribe('stop', self.mgr.stop) 
     74        self.httpserver, self.bind_addr = self.httpserver_from_self(server) 
     75        self.start() 
    10276     
    10377    def httpserver_from_self(self, httpserver=None): 
     
    11993     
    12094    def start(self): 
    121         """Start all registered HTTP servers.""" 
    122         self.mgr.start() 
    123      
    124     def wait(self, httpserver=None): 
    125         """Wait until the HTTP server is ready to receive requests. 
    126          
    127         If no httpserver is specified, wait for all registered httpservers. 
    128         """ 
    129         self.mgr.wait(httpserver) 
    130      
    131     def stop(self): 
    132         """Stop all HTTP servers.""" 
    133         self.mgr.stop() 
    134      
    135     def restart(self): 
    136         """Restart all HTTP servers.""" 
    137         self.mgr.restart() 
     95        """Start the HTTP server.""" 
     96        if not self.httpserver: 
     97            self.httpserver, self.bind_addr = self.httpserver_from_self() 
     98        ServerAdapter.start(self) 
     99    start.priority = 75 
    138100     
    139101    def base(self): 
    140         """Return the base (scheme://host) for this server manager.""" 
     102        """Return the base (scheme://host) for this server.""" 
    141103        if self.socket_file: 
    142104            return self.socket_file 
  • trunk/cherrypy/restsrv/plugins.py

    r1816 r1824  
    1717     
    1818    def subscribe(self): 
    19         """Register this monitor as a (multi-channel) listener on the bus.""" 
     19        """Register this object as a (multi-channel) listener on the bus.""" 
    2020        for channel in self.bus.listeners: 
    2121            method = getattr(self, channel, None) 
     
    2424     
    2525    def unsubscribe(self): 
    26         """Unregister this monitor as a listener on the bus.""" 
     26        """Unregister this object as a listener on the bus.""" 
    2727        for channel in self.bus.listeners: 
    2828            method = getattr(self, channel, None) 
     
    189189        # forking has issues with threads: 
    190190        # http://www.opengroup.org/onlinepubs/000095399/functions/fork.html 
    191         # " ... The general problem with making fork() work in a multi-threaded worl
    192         #  is what to do with all of the threads. ...
     191        # "The general problem with making fork() work in a multi-threade
     192        #  world is what to do with all of the threads...
    193193        # So we check for active threads: 
    194194        if threading.activeCount() != 1: 
    195             self.bus.log('There are more than one active threads. Daemonizing now may cause strange failures.') 
     195            self.bus.log('There are more than one active threads. ' 
     196                         'Daemonizing now may cause strange failures.') 
    196197            self.bus.log(str(threading.enumerate())) 
    197  
     198         
    198199        # See http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16 
    199200        # (or http://www.faqs.org/faqs/unix-faq/programmer/faq/ section 1.7) 
     
    302303        """Start our callback in its own perpetual timer thread.""" 
    303304        if self.frequency > 0: 
    304             threadname = "restsrv %s" % self.__class__.__name__ 
    305             self.thread = PerpetualTimer(self.frequency, self.callback) 
    306             self.thread.setName(threadname) 
    307             self.thread.start() 
    308             self.bus.log("Started thread %r." % threadname) 
     305            if self.thread is None: 
     306                threadname = "restsrv %s" % self.__class__.__name__ 
     307                self.thread = PerpetualTimer(self.frequency, self.callback) 
     308                self.thread.setName(threadname) 
     309                self.thread.start() 
     310                self.bus.log("Started thread %r." % threadname) 
     311            else: 
     312                self.bus.log("Thread %r already started." % threadname) 
    309313    start.priority = 70 
    310314     
    311315    def stop(self): 
    312316        """Stop our callback's perpetual timer thread.""" 
    313         if self.thread: 
     317        if self.thread is None: 
     318            self.bus.log("No thread running for %s." % self.__class__.__name__) 
     319        else: 
    314320            if self.thread is not threading.currentThread(): 
    315321                self.thread.cancel() 
     
    338344    def start(self): 
    339345        """Start our own perpetual timer thread for self.run.""" 
    340         self.mtimes = {} 
     346        if self.thread is None: 
     347            self.mtimes = {} 
    341348        Monitor.start(self) 
    342349    start.priority = 70  
  • trunk/cherrypy/restsrv/servers.py

    r1818 r1824  
    1 """Manage a set of HTTP servers.""" 
     1"""Adapt an HTTP server.""" 
    22 
    33import socket 
     
    66 
    77 
    8 class ServerManager(object): 
    9     """Manager for a set of HTTP servers. 
    10      
    11     This is both a container and controller for HTTP servers and gateways, 
    12     which are kept in Server.httpservers, a dictionary of the form: 
    13     {httpserver: bind_addr} where 'bind_addr' is usually a (host, port) 
    14     tuple. 
     8class ServerAdapter(object): 
     9    """Adapter for an HTTP server. 
    1510     
    1611    If you need to start more than one HTTP server (to serve on multiple 
    1712    ports, or protocols, etc.), you can manually register each one and then 
    18     control them all
     13    start them all with bus.start
    1914     
    20         s1 = MyWSGIServer(host='0.0.0.0', port=80) 
    21         s2 = another.HTTPServer(host='127.0.0.1', SSL=True) 
    22         server.httpservers = {s1: ('0.0.0.0', 80), 
    23                               s2: ('127.0.0.1', 443)} 
    24         server.start() 
    25      
    26     The start, wait, restart, and stop methods control all registered 
    27     httpserver objects at once. 
     15        s1 = ServerAdapter(bus, MyWSGIServer(host='0.0.0.0', port=80)) 
     16        s2 = ServerAdapter(bus, another.HTTPServer(host='127.0.0.1', SSL=True)) 
     17        s1.subscribe() 
     18        s2.subscribe() 
     19        bus.start() 
    2820    """ 
    2921     
    30      
    31     def __init__(self, bus): 
     22    def __init__(self, bus, httpserver=None, bind_addr=None): 
    3223        self.bus = bus 
    33         self.httpservers = {} 
     24        self.httpserver = httpserver 
     25        self.bind_addr = bind_addr 
    3426        self.interrupt = None 
     27        self.running = False 
    3528     
    3629    def subscribe(self): 
     
    3831        self.bus.subscribe('stop', self.stop) 
    3932     
     33    def unsubscribe(self): 
     34        self.bus.unsubscribe('start', self.start) 
     35        self.bus.unsubscribe('stop', self.stop) 
     36     
    4037    def start(self): 
    41         """Start all registered HTTP servers.""" 
    42         self.interrupt = None 
    43         if not self.httpservers: 
    44             raise ValueError("No HTTP servers have been created.") 
    45         for httpserver in self.httpservers: 
    46             self._start_http(httpserver) 
    47     start.priority = 75 
    48      
    49     def _start_http(self, httpserver): 
    50         """Start the given httpserver in a new thread.""" 
    51         bind_addr = self.httpservers[httpserver] 
    52         if isinstance(bind_addr, tuple): 
    53             wait_for_free_port(*bind_addr) 
    54             host, port = bind_addr 
     38        """Start the HTTP server.""" 
     39        if isinstance(self.bind_addr, tuple): 
     40            host, port = self.bind_addr 
    5541            on_what = "%s:%s" % (host, port) 
    5642        else: 
    57             on_what = "socket file: %s" % bind_addr 
     43            on_what = "socket file: %s" % self.bind_addr 
    5844         
    59         t = threading.Thread(target=self._start_http_thread, args=(httpserver,)) 
     45        if self.running: 
     46            self.bus.log("Already serving on %s" % on_what) 
     47            return 
     48         
     49        self.interrupt = None 
     50        if not self.httpserver: 
     51            raise ValueError("No HTTP server has been created.") 
     52         
     53        # Start the httpserver in a new thread. 
     54        if isinstance(self.bind_addr, tuple): 
     55            wait_for_free_port(*self.bind_addr) 
     56         
     57        t = threading.Thread(target=self._start_http_thread) 
    6058        t.setName("HTTPServer " + t.getName()) 
    6159        t.start() 
    6260         
    63         self.wait(httpserver) 
     61        self.wait() 
     62        self.running = True 
    6463        self.bus.log("Serving on %s" % on_what) 
     64    start.priority = 75 
    6565     
    66     def _start_http_thread(self, httpserver): 
    67         """HTTP servers MUST be started in new threads, so that the 
     66    def _start_http_thread(self): 
     67        """HTTP servers MUST be running in new threads, so that the 
    6868        main thread persists to receive KeyboardInterrupt's. If an 
    6969        exception is raised in the httpserver's thread then it's 
    70         trapped here, and the bus (and therefore our httpservers
     70        trapped here, and the bus (and therefore our httpserver
    7171        are shut down. 
    7272        """ 
    7373        try: 
    74             httpserver.start() 
     74            self.httpserver.start() 
    7575        except KeyboardInterrupt, exc: 
    76             self.bus.log("<Ctrl-C> hit: shutting down HTTP servers") 
     76            self.bus.log("<Ctrl-C> hit: shutting down HTTP server") 
    7777            self.interrupt = exc 
    7878            self.bus.stop() 
    7979        except SystemExit, exc: 
    80             self.bus.log("SystemExit raised: shutting down HTTP servers") 
     80            self.bus.log("SystemExit raised: shutting down HTTP server") 
    8181            self.interrupt = exc 
    8282            self.bus.stop() 
     
    8686            self.interrupt = sys.exc_info()[1] 
    8787            self.bus.log("Error in HTTP server: shutting down", 
    88                             traceback=True) 
     88                         traceback=True) 
    8989            self.bus.stop() 
    9090            raise 
    9191     
    92     def wait(self, httpserver=None): 
    93         """Wait until the HTTP server is ready to receive requests. 
     92    def wait(self): 
     93        """Wait until the HTTP server is ready to receive requests.""" 
     94        while not getattr(self.httpserver, "ready", False): 
     95            if self.interrupt: 
     96                raise self.interrupt 
     97            time.sleep(.1) 
    9498         
    95         If no httpserver is specified, wait for all registered httpservers. 
    96         """ 
    97         if httpserver is None: 
    98             httpservers = self.httpservers.items() 
    99         else: 
    100             httpservers = [(httpserver, self.httpservers[httpserver])] 
    101          
    102         for httpserver, bind_addr in httpservers: 
    103             while not getattr(httpserver, "ready", False): 
    104                 if self.interrupt: 
    105                     raise self.interrupt 
    106                 time.sleep(.1) 
    107              
    108             # Wait for port to be occupied 
    109             if isinstance(bind_addr, tuple): 
    110                 host, port = bind_addr 
    111                 wait_for_occupied_port(host, port) 
     99        # Wait for port to be occupied 
     100        if isinstance(self.bind_addr, tuple): 
     101            host, port = self.bind_addr 
     102            wait_for_occupied_port(host, port) 
    112103     
    113104    def stop(self): 
    114         """Stop all HTTP servers.""" 
    115         for httpserver, bind_addr in self.httpservers.items()
    116             # httpstop() MUST block until the server is *truly* stopped. 
    117             httpserver.stop() 
     105        """Stop the HTTP server.""" 
     106        if self.running
     107            # stop() MUST block until the server is *truly* stopped. 
     108            self.httpserver.stop() 
    118109            # Wait for the socket to be truly freed. 
    119             if isinstance(bind_addr, tuple): 
    120                 wait_for_free_port(*bind_addr) 
    121             self.bus.log("HTTP Server %s shut down" % httpserver) 
     110            if isinstance(self.bind_addr, tuple): 
     111                wait_for_free_port(*self.bind_addr) 
     112            self.running = False 
     113            self.bus.log("HTTP Server %s shut down" % self.httpserver) 
     114        else: 
     115            self.bus.log("HTTP Server %s already shut down" % self.httpserver) 
     116    stop.priority = 25 
    122117     
    123118    def restart(self): 
    124         """Restart all HTTP servers.""" 
     119        """Restart the HTTP server.""" 
    125120        self.stop() 
    126121        self.start() 
  • trunk/cherrypy/restsrv/win32.py

    r1757 r1824  
    11"""Windows service for restsrv. Requires pywin32.""" 
    22 
     3import os 
    34import thread 
    45import win32api 
     
    5253            return self.events[state] 
    5354        except KeyError: 
    54             event = win32event.CreateEvent(None, 0, 0, None) 
     55            event = win32event.CreateEvent(None, 0, 0, 
     56                                           u"WSPBus %s Event (pid=%r)" % 
     57                                           (state.name, os.getpid())) 
    5558            self.events[state] = event 
    5659            return event 
     
    7073        argument is ignored. 
    7174        """ 
     75        # Don't wait for an event that beat us to the punch ;) 
     76        if self.state == state: 
     77            return 
     78         
    7279        event = self._get_state_event(state) 
    7380        try: 
  • trunk/cherrypy/restsrv/wspbus.py

    r1820 r1824  
    7575class _StateEnum(object): 
    7676    class State(object): 
    77         pass 
     77        name = None 
     78        def __repr__(self): 
     79            return "states.%s" % self.name 
     80     
     81    def __setattr__(self, key, value): 
     82        if isinstance(value, self.State): 
     83            value.name = key 
     84        object.__setattr__(self, key, value) 
    7885states = _StateEnum() 
    7986states.STOPPED = states.State() 
  • trunk/cherrypy/test/helper.py

    r1760 r1824  
    110110    cherrypy.config.reset() 
    111111    setConfig(conf) 
    112     cherrypy.server.quickstart(server
     112    cherrypy.signal_handler.subscribe(
    113113    # The Pybots automatic testing system needs the suite to exit 
    114114    # with a non-zero value if there were any problems. 
     
    147147    apps.sort() 
    148148    apps.reverse() 
    149     for s in cherrypy.server.httpservers: 
    150         s.wsgi_app.apps = apps 
     149    cherrypy.server.httpserver.wsgi_app.apps = apps 
    151150 
    152151def _run_test_suite_thread(moduleNames, conf): 
  • trunk/cherrypy/test/modpy.py

    r1688 r1824  
    5656 
    5757 
    58 APACHE_PATH = "apache
     58APACHE_PATH = "httpd
    5959CONF_PATH = "test_mp.conf" 
    6060 
     
    128128        mod.setup_server() 
    129129         
     130        cherrypy.server.unsubscribe() 
    130131        cherrypy.engine.start() 
    131132    from mod_python import apache 
  • trunk/cherrypy/test/modwsgi.py

    r1802 r1824  
    141141            "engine.SIGTERM": None, 
    142142            }) 
     143        cherrypy.server.unsubscribe() 
    143144        cherrypy.engine.start(blocking=False) 
    144145    return cherrypy.tree(environ, start_response) 
  • trunk/cherrypy/test/test_conn.py

    r1786 r1824  
    202202        old_timeout = None 
    203203        try: 
    204             httpserver = cherrypy.server.httpservers.keys()[0] 
     204            httpserver = cherrypy.server.httpserver 
    205205            old_timeout = httpserver.timeout 
    206206        except (AttributeError, IndexError): 
  • trunk/cherrypy/test/test_states.py

    r1815 r1824  
    197197                self.assertNoHeader("Connection") 
    198198                 
    199                 cherrypy.server.httpservers.keys()[0].interrupt = KeyboardInterrupt 
     199                cherrypy.server.httpserver.interrupt = KeyboardInterrupt 
    200200                engine.block() 
    201201                 
     
    328328            self.fail("Process failed to return nonzero exit code.") 
    329329 
    330     def test_6_Start_Error_With_Daemonize(self): 
     330 
     331class DaemonizeTests(helper.CPWebCase): 
     332     
     333    def test_1_Daemonize(self): 
    331334        if not self.server_class: 
    332335            print "skipped (no server) ", 
     336            return 
     337        if os.name not in ['posix']:  
     338            print "skipped (not on posix) ", 
     339            return 
     340         
     341        # Start the demo script in a new process 
     342        demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__), 
     343                                  "test_states_demo.py") 
     344        host = cherrypy.server.socket_host 
     345        port = cherrypy.server.socket_port 
     346        cherrypy._cpserver.wait_for_free_port(host, port) 
     347         
     348        args = [sys.executable, demoscript, host, str(port), '-daemonize'] 
     349        if self.scheme == "https": 
     350            args.append('-ssl') 
     351        # Spawn the process and wait, when this returns, the original process 
     352        # is finished.  If it daemonized properly, we should still be able 
     353        # to access pages. 
     354        exit_code = os.spawnl(os.P_WAIT, sys.executable, *args) 
     355        cherrypy._cpserver.wait_for_occupied_port(host, port) 
     356         
     357        # Give the server some time to start up 
     358        time.sleep(2) 
     359         
     360        # Get the PID from the file. 
     361        pid = int(open(PID_file_path).read()) 
     362        try: 
     363            # Just get the pid of the daemonization process. 
     364            self.getPage("/pid") 
     365            self.assertStatus(200) 
     366            page_pid = int(self.body) 
     367            self.assertEqual(page_pid, pid) 
     368        finally: 
     369            # Shut down the spawned process 
     370            self.getPage("/stop") 
     371         
     372        try: 
     373            print os.waitpid(pid, 0) 
     374        except OSError, x: 
     375            if x.args != (10, 'No child processes'): 
     376                raise 
     377         
     378        # Wait until here to test the exit code because we want to ensure 
     379        # that we wait for the daemon to finish running before we fail. 
     380        if exit_code != 0: 
     381            self.fail("Daemonized process failed to exit cleanly") 
     382     
     383    def test_2_Start_Error_With_Daemonize(self): 
     384        if not self.server_class: 
     385            print "skipped (no server) ", 
     386            return 
     387        if os.name not in ['posix']:  
     388            print "skipped (not on posix) ", 
    333389            return 
    334390         
     
    351407 
    352408 
    353 class DaemonizeTest(helper.CPWebCase): 
    354      
    355     def test_Daemonize(self): 
    356         if not self.server_class: 
    357             print "skipped (no server) ", 
    358             return 
    359         if os.name not in ['posix']:  
    360             print "skipped (not on posix) ", 
    361             return 
    362          
    363         # Start the demo script in a new process 
    364         demoscript = os.path.join(os.getcwd(), os.path.dirname(__file__), 
    365                                   "test_states_demo.py") 
    366         host = cherrypy.server.socket_host 
    367         port = cherrypy.server.socket_port 
    368         cherrypy._cpserver.wait_for_free_port(host, port) 
    369          
    370         args = [sys.executable, demoscript, host, str(port), '-daemonize'] 
    371         if self.scheme == "https": 
    372             args.append('-ssl') 
    373         # Spawn the process and wait, when this returns, the original process 
    374         # is finished.  If it daemonized properly, we should still be able 
    375         # to access pages. 
    376         exit_code = os.spawnl(os.P_WAIT, sys.executable, *args) 
    377         cherrypy._cpserver.wait_for_occupied_port(host, port) 
    378          
    379         # Give the server some time to start up 
    380         time.sleep(2) 
    381          
    382         # Get the PID from the file. 
    383         pid = int(open(PID_file_path).read()) 
    384         try: 
    385             # Just get the pid of the daemonization process. 
    386             self.getPage("/pid") 
    387             self.assertStatus(200) 
    388             page_pid = int(self.body) 
    389             self.assertEqual(page_pid, pid) 
    390         finally: 
    391             # Shut down the spawned process 
    392             self.getPage("/stop") 
    393          
    394         try: 
    395             print os.waitpid(pid, 0) 
    396         except OSError, x: 
    397             if x.args != (10, 'No child processes'): 
    398                 raise 
    399          
    400         # Wait until here to test the exit code because we want to ensure 
    401         # that we wait for the daemon to finish running before we fail. 
    402         if exit_code != 0: 
    403             self.fail("Daemonized process failed to exit cleanly") 
    404  
    405  
    406409def run(server, conf): 
    407410    helper.setConfig(conf) 
    408411    ServerStateTests.server_class = server 
    409     DaemonizeTest.server_class = server 
     412    DaemonizeTests.server_class = server 
    410413    suite = helper.CPTestLoader.loadTestsFromTestCase(ServerStateTests) 
    411     daemon_suite = helper.CPTestLoader.loadTestsFromTestCase(DaemonizeTest
     414    daemon_suite = helper.CPTestLoader.loadTestsFromTestCase(DaemonizeTests
    412415    try: 
    413416        try: 
     
    438441     
    439442    if host: 
    440         DaemonizeTest.HOST = ServerStateTests.HOST = host 
     443        DaemonizeTests.HOST = ServerStateTests.HOST = host 
    441444     
    442445    if port: 
    443         DaemonizeTest.PORT = ServerStateTests.PORT = port 
     446        DaemonizeTests.PORT = ServerStateTests.PORT = port 
    444447     
    445448    if ssl: 
     
    448451        conf['server.ssl_certificate'] = serverpem 
    449452        conf['server.ssl_private_key'] = serverpem 
    450         DaemonizeTest.scheme = ServerStateTests.scheme = "https" 
    451         DaemonizeTest.HTTP_CONN = ServerStateTests.HTTP_CONN = httplib.HTTPSConnection 
     453        DaemonizeTests.scheme = ServerStateTests.scheme = "https" 
     454        DaemonizeTests.HTTP_CONN = ServerStateTests.HTTP_CONN = httplib.HTTPSConnection 
    452455     
    453456    def _run(server): 
  • trunk/cherrypy/test/test_states_demo.py

    r1815 r1824  
    2929     
    3030    def stop(self): 
     31        # This handler might be called before the engine is STARTED if an 
     32        # HTTP worker thread handles it before the HTTP server returns 
     33        # control to engine.start. We avoid that race condition here 
     34        # by waiting for the Bus to be STARTED. 
     35        cherrypy.engine.block(state=cherrypy.engine.states.STARTED) 
    3136        cherrypy.engine.stop() 
    3237    stop.exposed = True 
     
    3843            "log.screen": False, 
    3944            "log.error_file": os.path.join(thisdir, 'test_states_demo.error.log'), 
     45            "log.access_file": os.path.join(thisdir, 'test_states_demo.access.log'), 
    4046            } 
    4147     
     
    6268        plugins.PIDFile(cherrypy.engine, PID_file_path).subscribe() 
    6369     
    64     cherrypy.engine.subscribe('start', cherrypy.server.quickstart, priority=75) 
    65      
    6670    if '-starterror' in sys.argv[3:]: 
    6771        cherrypy.engine.subscribe('start', lambda: 1/0, priority=6) 
  • trunk/cherrypy/test/test_tools.py

    r1661 r1824  
    259259        old_timeout = None 
    260260        try: 
    261             httpserver = cherrypy.server.httpservers.keys()[0] 
     261            httpserver = cherrypy.server.httpserver 
    262262            old_timeout = httpserver.timeout 
    263263        except (AttributeError, IndexError): 
  • trunk/cherrypy/test/test_wsgi_ns.py

    r1804 r1824  
    7878     
    7979    def test_pipeline(self): 
    80         if not cherrypy.server.httpservers
     80        if not cherrypy.server.httpserver
    8181            print "skipped ", 
    8282            return 

Hosted by WebFaction

Log in as guest/cpguest to create tickets