Is it possible to fasten the import of cgi?

Cecil Westerhof dummy at dummy.nl
Fri Jan 19 12:28:02 EST 2007


Gabriel Genellina wrote:

> I'll try to explain better: the cgi *protocol* (I'm not talking about the
> cgi *module*) requires a *new* python process to be created on *each*
> request. Try to measure the time it takes to launch Python, that is, the
> time from when you type `python ENTER` on your shell and the interpreter
> prompt appears. That time is wasted for *every* cgi request, and I bet it
> is much greater than the 95 ms you measure importing a module (be it cgi
> or whatever). You'll gain much more responsiveness if you can switch to
> another protocol, be it FastCGI, WSGI, mod_python or another.

The import of the cgi module takes about 95 milliseconds and the browsers
takes around 260 milliseconds to fetch the xml-page. This is why I thought
it to be important, but I think you are right, I should not worry about
this and switch to another protocol. Is not possible with the current
hosting provider, but I'll switch.
Pointers where to look for in selecting the protocol are apreciated.


> Anyway, comparing the import time between os, sys, and cgi is not very
> meaningful. sys is a builtin module, so "import sys" does very little. os
> is likely to be already imported by the time your script begins, so
> "import os" just verifies that os is already in sys.modules. "import cgi"
> is the only example when Python actually has to load something, so it's
> not a surprise if it takes longer.

Okay, thank you for the explanation.





More information about the Python-list mailing list