Changeset 943
- Timestamp:
- 01/26/06 06:58:24
- Files:
-
- trunk/cherrypy/_cpserver.py (modified) (6 diffs)
- trunk/cherrypy/test/helper.py (modified) (2 diffs)
- trunk/cherrypy/test/test_noserver.py (modified) (1 diff)
- trunk/cherrypy/test/test_states.py (modified) (7 diffs)
- trunk/cherrypy/test/test_xmlrpc_filter.py (modified) (1 diff)
- trunk/docs/book/xml/apireference.xml (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpserver.py
r905 r943 43 43 self.onStopThreadList = [] 44 44 45 def start(self, initOnly=False, serverClass=_missing): 45 def start(self, init_only = False, server_class = _missing, 46 initOnly = None, serverClass = None): 46 47 """Main function. MUST be called from the main thread. 47 48 … … 49 50 Set serverClass to None to skip starting any HTTP server. 50 51 """ 52 53 # Read old variable names for backward compatibility 54 if initOnly is not None: 55 init_only = initOnly 56 if serverClass is not None: 57 server_class = serverClass 58 51 59 self.state = STARTING 52 60 self.interrupt = None … … 54 62 conf = cherrypy.config.get 55 63 56 if server Class is _missing:57 server Class = conf("server.class", _missing)58 if server Class is _missing:64 if server_class is _missing: 65 server_class = conf("server.class", _missing) 66 if server_class is _missing: 59 67 import _cpwsgi 60 server Class = _cpwsgi.WSGIServer61 elif server Class and isinstance(serverClass, basestring):68 server_class = _cpwsgi.WSGIServer 69 elif server_class and isinstance(server_class, basestring): 62 70 # Dynamically load the class from the given string 63 server Class = cptools.attributes(serverClass)64 65 self.blocking = not init Only66 self.httpserverclass = server Class71 server_class = cptools.attributes(server_class) 72 73 self.blocking = not init_only 74 self.httpserverclass = server_class 67 75 68 76 # Hmmm...we *could* check config in _start instead, but I think … … 70 78 check_config() 71 79 72 # Autoreload, but check server Class. If None, we're not starting80 # Autoreload, but check server_class. If None, we're not starting 73 81 # our own webserver, and therefore could do Very Bad Things when 74 82 # autoreload calls sys.exit. 75 if server Class is not None:83 if server_class is not None: 76 84 if conf('autoreload.on', False): 77 85 try: … … 258 266 259 267 def start_with_callback(self, func, args=None, kwargs=None, 260 server Class=_missing):268 server_class = _missing, serverClass = None): 261 269 """Start, then callback the given func in a new thread.""" 270 271 # Read old name for backward compatibility 272 if serverClass is not None: 273 server_class = None 274 262 275 if args is None: 263 276 args = () … … 271 284 threading.Thread(target=_callback, args=args, kwargs=kwargs).start() 272 285 273 self.start(server Class=serverClass)286 self.start(server_class = server_class) 274 287 275 288 trunk/cherrypy/test/helper.py
r917 r943 199 199 setConfig(conf) 200 200 cherrypy.server.start_with_callback(_run_test_suite_thread, 201 args=(moduleNames, conf), 202 serverClass=server) 201 args = (moduleNames, conf), server_class = server) 203 202 204 203 def _run_test_suite_thread(moduleNames, conf): … … 219 218 conf = {} 220 219 setConfig(conf) 221 cherrypy.server.start_with_callback(_test_main_thread, serverClass=server) 220 cherrypy.server.start_with_callback(_test_main_thread, 221 server_class = server) 222 222 223 223 def _test_main_thread(): trunk/cherrypy/test/test_noserver.py
r778 r943 28 28 29 29 cherrypy.config.update({"server.environment": "production"}) 30 cherrypy.server.start(server Class=None)30 cherrypy.server.start(server_class = None) 31 31 trunk/cherrypy/test/test_states.py
r897 r943 65 65 66 66 # Test server start 67 cherrypy.server.start(True, self.server Class)67 cherrypy.server.start(True, self.server_class) 68 68 self.assertEqual(cherrypy.server.state, 1) 69 69 70 if self.server Class:70 if self.server_class: 71 71 host = cherrypy.config.get('server.socket_host') 72 72 port = cherrypy.config.get('server.socket_port') … … 94 94 95 95 def test_1_Restart(self): 96 cherrypy.server.start(True, self.server Class)96 cherrypy.server.start(True, self.server_class) 97 97 98 98 # The db_connection should be running now … … 129 129 130 130 def test_2_KeyboardInterrupt(self): 131 if self.server Class:131 if self.server_class: 132 132 133 133 # Raise a keyboard interrupt in the HTTP server's main thread. … … 138 138 139 139 # We must start the server in this, the main thread 140 cherrypy.server.start(False, self.server Class)140 cherrypy.server.start(False, self.server_class) 141 141 # Time passes... 142 142 self.assertEqual(cherrypy.server.httpserver, None) … … 156 156 threading.Thread(target=interrupt).start() 157 157 158 cherrypy.server.start(False, self.server Class)158 cherrypy.server.start(False, self.server_class) 159 159 # Time passes... 160 160 self.assertEqual(cherrypy.server.httpserver, None) … … 166 166 def test_3_ConfigErrors(self): 167 167 cherrypy.config.update({'server.environment': 'destruction'}) 168 168 169 try: 169 170 self.assertRaises(cherrypy.WrongConfigValue, 170 cherrypy.server.start, True, self.serverClass)171 cherrypy.server.start, True, self.server_class) 171 172 finally: 172 173 cherrypy.server.stop() … … 177 178 def run(server, conf): 178 179 helper.setConfig(conf) 179 ServerStateTests.server Class = server180 ServerStateTests.server_class = server 180 181 suite = helper.CPTestLoader.loadTestsFromTestCase(ServerStateTests) 181 182 try: trunk/cherrypy/test/test_xmlrpc_filter.py
r856 r943 137 137 if __name__ == '__main__': 138 138 from cherrypy import _cpwsgi 139 server Class = _cpwsgi.WSGIServer140 helper.testmain(server Class)139 server_class = _cpwsgi.WSGIServer 140 helper.testmain(server_class) 141 141 trunk/docs/book/xml/apireference.xml
r942 r943 186 186 <title>cherrypy.server</title> 187 187 <section> 188 <title>cherrypy.server.start(init Only=False, serverClass=_missing)</title>188 <title>cherrypy.server.start(init_only = False, server_class = _missing)</title> 189 189 <para>Start the CherryPy Server. Simple websites may call this without any arguments, to 190 run the default server. If init Only is False (the default), this function will block190 run the default server. If init_only is False (the default), this function will block 191 191 until KeyboardInterrupt or SystemExit is raised, so that the process will persist. When 192 192 using one of the built-in HTTP servers, you should leave this set to False. You should … … 194 194 (for example, when using Apache and mod_python with CherryPy), in which case the foreign 195 195 HTTP server should do its own process-management.</para> 196 <para>Use the server Class argument to specify that you wish to use an HTTP server other196 <para>Use the server_class argument to specify that you wish to use an HTTP server other 197 197 than the default, built-in WSGIServer. If missing, config.get("server.class") will be 198 198 checked for an alternate value; otherwise, the default is used. Possible alternate values … … 217 217 <listitem> 218 218 <para><code>None</code>: this will not load any HTTP server. Note that this is 219 not the default; the default (if server Class is not given) is to load the219 not the default; the default (if server_class is not given) is to load the 220 220 WSGIServer.</para> 221 221 </listitem> … … 225 225 </itemizedlist> 226 226 <para>You <emphasis>must</emphasis> call this function from Python's main thread, and set 227 init Only to False, if you want CherryPy to shut down when KeyboardInterrupt or SystemExit227 init_only to False, if you want CherryPy to shut down when KeyboardInterrupt or SystemExit 228 228 are raised (including Ctrl-C). The only time you might want to do otherwise is if you run 229 229 CherryPy as a Windows service, or as an extension to, say, mod_python, and even then, you … … 232 232 <section> 233 233 <title>cherrypy.server.blocking</title> 234 <para>If the "init Only" argument to server.start is True, this will be False, and234 <para>If the "init_only" argument to server.start is True, this will be False, and 235 235 vice-versa.</para> 236 236 </section> … … 274 274 <section> 275 275 <title>cherrypy.server.start_with_callback(func, args=(), kwargs={}, 276 server Class=_missing)</title>276 server_class = _missing)</title> 277 277 <para>Since server.start usually blocks, use this to easily run another function in a new 278 278 thread. It starts the new thread and then runs server.start. The new thread automatically

