Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could somebody give me a high-level technical overview of WSGI details behind the scenes vs other web interface approaces with Python?

Firstly:

  1. I understand what WSGI is and how to use it
  2. I understand what "other" methods (Apache mod-python, fcgi, et al) are, and how to use them
  3. I understand their practical differences

What I don't understand is how each of the various "other" methods work compared to something like UWSGI, behind the scenes. Does your server (Nginx, etc) route the request to your WSGI application and UWSGI creates a new Python interpreter for each request routed to it? How much different is is from the other more traditional / monkey patched methods is WSGI (aside from the different, easier Python interface that WSGI offers)? What light bulb moment am I missing?

like image 403
orokusaki Avatar asked Apr 29 '10 18:04

orokusaki


People also ask

What is WSGI a readable explanation for Python developers?

The WSGI represents for web server gateway interface. It's a standard designed by the Python community to make the web development in Python easier. It builds a bridge between a Python web app and a server software.

Is WSGI a web server?

The Web Server Gateway Interface (WSGI, pronounced whiskey or WIZ-ghee) is a simple calling convention for web servers to forward requests to web applications or frameworks written in the Python programming language. The current version of WSGI, version 1.0.

Is WSGI a Python module?

The Web Server Gateway Interface (WSGI) is a standard interface between web server software and web applications written in Python. Having a standard interface makes it easy to use an application that supports WSGI with a number of different web servers.

What does a WSGI do?

WSGI stands for "Web Server Gateway Interface". It is used to forward requests from a web server (such as Apache or NGINX) to a backend Python web application or framework.


1 Answers

Except for CGI, a new Python interpreter is nearly never created per request. Read:

http://blog.dscpl.com.au/2009/03/python-interpreter-is-not-created-for.html

This was written in respect of mod_python but also applies to mod_wsgi and any WSGI hosting mechanism that uses persistent processes.

Also read:

http://www.python.org/dev/peps/pep-0333/#environ-variables

There you will find described the 'wsgi.run_once' variable described. This is used to indicate to a WSGI application when a hosting mechanism is used which would see a process only handling one request and then being exited, ie., CGI. Thus, write a test hello world application which dumps out the WSGI environment and see what it is set to for what you are using.

Also pay attention to the 'wsgi.multiprocess' and 'wsgi.multithread' variables. They tell you if a multi process server is being used such that there are multiple instances of your application handling requests at the same time. The 'wsgi.multithread' variable tells you if the process itself is handling multiple requests in concurrent threads in same process.

For more on multiprocess and multithread models in relation to Apache embedded systems, such as mod_python and mod_wsgi, and mod_wsgi daemon mode, see:

http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

like image 114
Graham Dumpleton Avatar answered Sep 23 '22 06:09

Graham Dumpleton