Jump to content

mod_python

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by AnomieBOT (talk | contribs) at 00:32, 16 August 2013 (Dating maintenance tags: {{Citation needed}}). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

mod_python is an Apache HTTP Server module that integrates the Python programming language into the Apache server. It is intended to replace Common Gateway Interface (CGI) as a method of executing Python scripts on a web server. The promised benefits are faster execution speed and maintaining data over multiple sessions. Although it is no longer actively developed, the official Apache mod_python page states: "This does not mean that it is 'dead' as some people have claimed. It simply means that the code and the project are mature enough when very little is required to maintain it."[1]

Benefits

Ordinary CGI execution starts a new process every time a connection is made to a script on the server. This works well in low- to medium-traffic sites, but does not scale well when used on a high-traffic site. There are methods of enhancing the performance of CGI, such as FastCGI, but it is often easier to use a specialized module to embed the desired language into the web server itself. This is what mod_python is designed to do. Since the process does not terminate after the script executes, as CGI does, persistent data, such as database connections, can be stored. This can reduce script execution overhead.

Since mod_python modules are integrated with the web server, they can do almost anything an Apache module written in C can: implement protocols other than HTTP, filter the request and response, determine a document's content type, and more.

Another advantage to mod_python is that it can talk directly to Apache's interface and control its core system through handlers that the programmer specifies in the Apache configuration file. Client requests directed at that specific directory will be processed by mod_python and a "Main" function that handles all requests, rather than by Apache.

Using mod_python also has the advantage of Python Server Pages (PSP), a way to embed Python code into HTML pages, similar to ASP, PHP, and JavaServer Pages (JSP).

Problems

[citation needed]

Embedding the Python interpreter (and different Python applications) directly into the Apache process is not without problems, especially when looking at shared Python web application hosting:

  • all hosted applications run under the same uid/gid (bad for security and separation of different users' web applications)
  • restarting Apache (usually needs root user privileges) might be necessary:
    • if some Python code malfunctions
    • in case of memory leaks
    • after a user upgraded their Python code

Additionally to the problematic embedded mode offered by Mod_python, mod_wsgi (another alternative Apache module for running Python web applications) also offers a daemon mode that is more secure and easier handled for a non-root webhosting user.

History

The initial implementation of mod_python was written by Aaron Watters and distributed on the CD for the book "Internet Programming with Python". [citation needed] The first version of mod_python as modified by Gregory Trubetskoy was released in 2000. In September 2002 mod_python was donated to the Apache Software Foundation and became part of the Apache HTTP Server project. The Apache Software Foundation June board meeting, which took place on June 16, 2010, unanimously passed a resolution to terminate Apache Quetzalcoatl Project (umbrella project for mod_python).[2]

See also

References