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

Changeset 1125

Show
Ignore:
Timestamp:
06/06/06 16:43:33
Author:
fumanchu
Message:

Removed cherrypy.NotReady?. Instead, cherrypy.engine will return HTTP 503 Service Unavailable, and cherrypy.server will raise IOError.

Files:

Legend:

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

    r1109 r1125  
    125125            time.sleep(.1) 
    126126            if self.interrupt: 
    127                 msg = "The CherryPy application engine errored" 
    128                 raise cherrypy.NotReady(msg, "ENGINE") 
     127                raise self.interrupt 
    129128     
    130129    def _is_ready(self): 
     
    143142        """ 
    144143        if self.state == STOPPED: 
    145             raise cherrypy.NotReady("The CherryPy engine has stopped.") 
     144            r = NotReadyRequest("The CherryPy engine has stopped.") 
    146145        elif self.state == STARTING: 
    147             raise cherrypy.NotReady("The CherryPy engine could not start.") 
    148          
    149         threadID = threading._get_ident() 
    150         if threadID not in self.seen_threads: 
    151              
    152             if cherrypy.codecoverage: 
    153                 from cherrypy.lib import covercp 
    154                 covercp.start() 
    155              
    156             i = len(self.seen_threads) + 1 
    157             self.seen_threads[threadID] = i 
    158              
    159             for func in self.on_start_thread_list: 
    160                 func(i) 
    161          
    162         r = self.request_class(client_address[0], client_address[1], 
    163                                remote_host, scheme) 
     146            r = NotReadyRequest("The CherryPy engine could not start.") 
     147        else: 
     148            # Only run on_start_thread_list if the engine is running. 
     149            threadID = threading._get_ident() 
     150            if threadID not in self.seen_threads: 
     151                 
     152                if cherrypy.codecoverage: 
     153                    from cherrypy.lib import covercp 
     154                    covercp.start() 
     155                 
     156                i = len(self.seen_threads) + 1 
     157                self.seen_threads[threadID] = i 
     158                 
     159                for func in self.on_start_thread_list: 
     160                    func(i) 
     161            r = self.request_class(client_address[0], client_address[1], 
     162                                   remote_host, scheme) 
    164163        cherrypy.serving.request = r 
    165164        cherrypy.serving.response = self.response_class() 
     
    184183        self.start() 
    185184 
     185 
     186class NotReadyRequest: 
     187     
     188    def __init__(self, msg): 
     189        self.msg = msg 
     190     
     191    def run(self, request_line, headers, rfile): 
     192        self.method = "GET" 
     193        cherrypy.HTTPError(503, self.msg).set_response() 
     194        cherrypy.response.finalize() 
     195        return cherrypy.response 
     196 
  • trunk/cherrypy/_cperror.py

    r1094 r1125  
    1111 
    1212class Error(Exception): 
    13     pass 
    14  
    15 class NotReady(Error): 
    16     """A request was made before the app server has been started.""" 
    1713    pass 
    1814 
  • trunk/cherrypy/_cpserver.py

    r1124 r1125  
    139139            return 
    140140     
    141     cherrypy.log("Port %s not free on %s" % (repr(port), repr(host)), 'HTTP') 
    142     raise cherrypy.NotReady("Port not free.") 
     141    msg = "Port %s not free on %s" % (repr(port), repr(host)) 
     142    cherrypy.log(msg, 'HTTP') 
     143    raise IOError(msg) 
    143144 
    144145def wait_for_occupied_port(host, port): 
     
    155156            time.sleep(.1) 
    156157     
    157     cherrypy.log("Port %s not bound on %s" % (repr(port), repr(host)), 'HTTP') 
    158     raise cherrypy.NotReady("Port not bound.") 
     158    msg = "Port %s not bound on %s" % (repr(port), repr(host)) 
     159    cherrypy.log(msg, 'HTTP') 
     160    raise IOError(msg) 
  • trunk/cherrypy/lib/httptools.py

    r1106 r1125  
    1414                      'The server encountered an unexpected condition ' 
    1515                      'which prevented it from fulfilling the request.') 
     16responseCodes[503] = ('Service Unavailable', 
     17                      'The server is currently unable to handle the ' 
     18                      'request due to a temporary overloading or ' 
     19                      'maintenance of the server.') 
    1620 
    1721 
  • trunk/cherrypy/test/test_states.py

    r1096 r1125  
    5555        if not self.server_class: 
    5656            # Without having called "cherrypy.engine.start()", we should 
    57             # get a NotReady error 
    58             self.assertRaises(cherrypy.NotReady, self.getPage, "/") 
     57            # get a 503 Service Unavailable response. 
     58            self.getPage("/") 
     59            self.assertStatus(503) 
    5960         
    6061        # And our db_connection should not be running 
     
    9192         
    9293        if not self.server_class: 
    93             # Once the server has stopped, we should get a NotReady 
     94            # Once the engine has stopped, we should get a 503 
    9495            # error again. (If we were running an HTTP server, 
    9596            # then the connection should not even be processed). 
    96             self.assertRaises(cherrypy.NotReady, self.getPage, "/") 
     97            self.getPage("/") 
     98            self.assertStatus(503) 
    9799         
    98100        # Block the main thread now and verify that stop() works. 

Hosted by WebFaction

Log in as guest/cpguest to create tickets