Converting Python CGI to WSGI scripts
nagle at animats.com
Wed Mar 17 07:34:21 CET 2010
Sebastian Bassi wrote:
> On Tue, Mar 16, 2010 at 2:18 PM, <python at bdurham.com> 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.
More information about the Python-list