Converting Python CGI to WSGI scripts

John Nagle nagle at
Wed Mar 17 07:34:21 CET 2010

Sebastian Bassi wrote:
> On Tue, Mar 16, 2010 at 2:18 PM,  <python at> wrote:
>> I have a few dozen simple Python CGI scripts.
>> Are there any advantages or disadvantages to rewriting these CGI scripts as
>> WSGI scripts?
> It depends of the script. WSGI should be faster since you don't start
> a Python instance for each call (as in CGI).

    It's almost always faster.  But be careful about global state.
Remember that WSGI/FCGI programs are really functions, called
over and over with a new transaction on each call.  So your
function has to be reusable.

    Things like initializing global variables at program load time,
rather than when the main function is called, may give trouble.
Also, be careful about leaving files, database connections, and
sockets open after the main function returns.

				John Nagle

More information about the Python-list mailing list