Apache: mod_python
One of the most interesting ways to use python is the Apache’s mod_python module. The mod_python module actually embeds a fully functional python intrepreter inside the apache web server.
This is most frequently used as powerful means to generate dynamic web pages.
The most common method of generating dynamic web pages is the CGI script. A CGI page is invoked each time a given page is requested. It reads the request, generates a reply and then terminates. This mimics the operation of HTTP, which at its core, works with a single request at a time. The next time a request is received, the CGI script is again invoked from scratch. This design enables the CGI script to be both language and server neutral. indeed all popular web servers and programming languages support them.
However this compatibility comes at a price & performance, Starting up a CGI script is slow. There’s operating system overhead involved while creating a new process. There’s overhead from the python interpreter when initializing and loading the script. CGI script that connect to databases hit especially hard, since they must establish new database connection each time a page is displayed. For these reasons CGI scripts are not suitable for high traffic sites.

The mod_python module is one answer to these problems. It actually embeds a full python interpreter inside the apache web server. your scripts are loaded only once per server process and only initialized then. Database connections can be established at the time of initialization and can be kept open throughout the life of web server process. whenever a page needs to be generated, a particular function is called, all data about the request is passed to it. This function has access to the environment created at the initialization time. so, for instance it can reuse the existing database connection.
while this scheme forces the use of apache web server, its advantage often outweigh its disadvantages, Read more…









