I would really like you to tell me with details about Whats and Whys, specific applications, etc.
Ho. Well, you asked for it!
Like Daniel, I personally use Apache with mod_wsgi. It’s still new enough that deploying it in some environments can be a struggle, but if you do build everything yourself, it’s pretty easy. I found it very reliable, even in earlier versions. Graham Dumpleton’s reinforcements for controlling him by himself.
However, it is important for me that WSGI applications run on all possible servers. There is a bit of a hole in this area right now: you have the WSGI standard telling you what the WSGI (application) does, but there is no deployment standardization; There is no single way to tell the web server where to find the application. There is also no standardized way to restart the server when it is updated.
The approach I took is to put:
all application logic in modules / packages, preferably in classes
all customizable settings for the website are done by subclassing the main application and redefining the elements
all deployment parameters for the server (for example, connecting to the factory database, mail relay settings) as parameters of the __init __ () class
one top-level application.py script that initializes the Application class with the correct deployment settings for the current server, then launches the application in such a way that it can work as a CGI script, mod_wsgi WSGIScriptAlias ​​(or Passenger, which apparently works the same) or can be associated with the command line
an auxiliary module that takes care of deployment problems and allows you to restart the application when the modules on which the application uses changes
So what application.py looks like at the end, it's something like:
#!/usr/bin/env python import os.path basedir= os.path.dirname(__file__) import MySQLdb def dbfactory(): return MySQLdb.connect(db= 'myappdb', unix_socket= '/var/mysql/socket', user= 'u', passwd= 'p') def appfactory(): import myapplication return myapplication.Application(basedir, dbfactory, debug= False) import wsgiwrap ismain= __name__=='__main__' libdir= os.path.join(basedir, 'system', 'lib') application= wsgiwrap.Wrapper(appfactory, libdir, 10, ismain)
wsgiwrap.Wrapper checks every 10 seconds to see if any of the application modules are updated in libdir, and if so, then some of the nasty sys.modules magic can reliably unload them. Then appfactory () will be called again to get a new instance of the updated application.
(You can also use command line tools such as
./application.py setup ./application.py daemon
to run any configuration hooks and background tasks provided by the called application is a bit like distutils. It also responds to start / stop / restart like init script.)
Another trick I use is setting deployment parameters for several servers (development / testing / production) in the same application.py script and sniff 'socket.gethostname () application to decide which set of parameters for a particular server to use.
At some point, I can pack wsgiwrap and release it (possibly under a different name). In the meantime, if you are interested, you can see the dogfood development version at http://www.doxdesk.com/file/software/py/v/wsgiwrap-0.5.py .