Changeset 1125
- Timestamp:
- 06/06/06 16:43:33
- Files:
-
- trunk/cherrypy/_cpengine.py (modified) (3 diffs)
- trunk/cherrypy/_cperror.py (modified) (1 diff)
- trunk/cherrypy/_cpserver.py (modified) (2 diffs)
- trunk/cherrypy/lib/httptools.py (modified) (1 diff)
- trunk/cherrypy/test/test_states.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpengine.py
r1109 r1125 125 125 time.sleep(.1) 126 126 if self.interrupt: 127 msg = "The CherryPy application engine errored" 128 raise cherrypy.NotReady(msg, "ENGINE") 127 raise self.interrupt 129 128 130 129 def _is_ready(self): … … 143 142 """ 144 143 if self.state == STOPPED: 145 r aise cherrypy.NotReady("The CherryPy engine has stopped.")144 r = NotReadyRequest("The CherryPy engine has stopped.") 146 145 elif self.state == STARTING: 147 r aise 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 covercp154 covercp.start()155 156 i = len(self.seen_threads) + 1157 self.seen_threads[threadID] = i158 159 for func in self.on_start_thread_list:160 f unc(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) 164 163 cherrypy.serving.request = r 165 164 cherrypy.serving.response = self.response_class() … … 184 183 self.start() 185 184 185 186 class 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 11 11 12 12 class Error(Exception): 13 pass14 15 class NotReady(Error):16 """A request was made before the app server has been started."""17 13 pass 18 14 trunk/cherrypy/_cpserver.py
r1124 r1125 139 139 return 140 140 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) 143 144 144 145 def wait_for_occupied_port(host, port): … … 155 156 time.sleep(.1) 156 157 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 14 14 'The server encountered an unexpected condition ' 15 15 'which prevented it from fulfilling the request.') 16 responseCodes[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.') 16 20 17 21 trunk/cherrypy/test/test_states.py
r1096 r1125 55 55 if not self.server_class: 56 56 # 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) 59 60 60 61 # And our db_connection should not be running … … 91 92 92 93 if not self.server_class: 93 # Once the server has stopped, we should get a NotReady94 # Once the engine has stopped, we should get a 503 94 95 # error again. (If we were running an HTTP server, 95 96 # then the connection should not even be processed). 96 self.assertRaises(cherrypy.NotReady, self.getPage, "/") 97 self.getPage("/") 98 self.assertStatus(503) 97 99 98 100 # Block the main thread now and verify that stop() works.

