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

root/branches/cherrypy-2.1/cherrypy/test/test_noserver.py

Revision 698 (checked in by fumanchu, 3 years ago)

Ugly fix for #321. cherrypy.server could really use some encapsulation now.

1. server.start now MUST be called from the main thread, or restart and interrupts won't work. You can stop and restart CherryPy safely now with the server.stop and server.restart methods. However, stop() only suspends the process; if you want to shut down the CP process, raise SystemExit? or KeyboardInterrupt?. If you need to do so in your own threads, set cherrypy._interrupt to an instance of one of those exceptions.

2. New cherrypy._httpserverclass attribute, so that threads can wait for the HTTP server to truly start.

3. server.start() now defaults serverClass to _missing, so if you were using None to get the WSGIServer, switch to _missing.

4. server has some new methods: start_app_server, start_http_server, stop_http_server, stop_app_server.

5. There's also a new start_with_callback function, so you don't have to code the threading yourself if you want to start the server but run another task in a new thread.

6. test/helper.py doesn't have startServer/stopServer methods anymore. Just call server.start/stop instead.

Line 
1 """Test WSGI servers and gateways, such as mod_python.
2
3 mod_python
4 ----------
5
6 Put the following four lines somewhere in your Apache2 .conf:
7
8 PythonImport cherrypy.test.test_noserver REDROVER.HQAMOR.amorhq.net
9 SetHandler python-program
10 PythonHandler wsgiref.modpython_gateway::handler
11 PythonOption application cherrypy._cpwsgi::wsgiApp
12
13 """
14
15 import cherrypy
16 from cherrypy import _cpwsgi
17
18 class HelloWorld:
19     def index(self):
20         return "Hello world!"
21     index.exposed = True
22     wsgi_asp = index
23
24 cherrypy.root = HelloWorld()
25 cherrypy.root.test = HelloWorld()
26
27 cherrypy.config.update({"server.environment": "production"})
28 cherrypy.server.start(serverClass=None)
29
Note: See TracBrowser for help on using the browser.

Hosted by WebFaction

Log in as guest/cpguest to create tickets