[Tutor] Re: display filter slow

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 18 Dec 2001 10:44:29 -0800 (PST)

On Tue, 18 Dec 2001, Prahlad Vaidyanathan wrote:

> Hi,
> On Mon, 17 Dec 2001 Prahlad Vaidyanathan spewed into the ether:
> [-- snip --]
> > As you can see, the script takes nearly thrice the amount of time as
> > without it. I'm sure there is a more efficient way of filtering my mail,
> > so any help would be appreciated.
> I know replying to one's own post is a Bad Thing, but I found out on my
> own, so I thought I should post it.
> The reason it was taking so long to start was that the python
> interpreter itself was taking a very long time to load. On startup,
> the interpreter tries to import a whole bunch of site-packages. All
> the packages it tried to import had a 'bad mtime' - hence it tried to
> byte-compile the .py file into the .pyc equivalent. Since I didn't
> have write-access to the /usr/lib/python2.0 directory, it complained,
> but continued nonetheless. But, the delay involved in recongising and
> reporting this problem caused the overall delay of the script.

Ah!  Put at the top of your script the following magic line:

#!/usr/local/bin/python -S

or something equivalent to this.  The important part is the '-S' part.  
Every Python script implicitely does an 'import site' for site-specific
customizations.  By using '-S', we're telling Python that we know what
we're doing, and to not do the import.

Try that, and see if your load time improves.