__file__ access extremely slow

Zac Burns zac256 at gmail.com
Sat Jun 6 03:08:42 EDT 2009


I think I have figured this out, thanks for your input.

The time comes from lazy modules related to e-mail importing on
attribute access, which is acceptable. Hence of course
why ImportError was sometime raised.

I originally was thinking that accessing __file__ was triggering some
mechanism that caused an attempt at importing other modules, but the
lazy import explanation makes much more sense.

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games



On Fri, Jun 5, 2009 at 2:15 AM, Gabriel Genellina<gagsl-py2 at yahoo.com.ar> wrote:
> En Fri, 05 Jun 2009 00:12:25 -0300, John Machin <sjmachin at lexicon.net>
> escribió:
>
>>> > (2) This will stop processing on the first object in sys.modules that
>>> > doesn't have a __file__ attribute. Since these objects aren't
>>> > *guaranteed* to be modules,
>>
>> Definitely not guaranteed to be modules. Python itself drops non-modules
>> in
>> there! Python 2.3 introduced four keys mapped to None -- one of these was
>> dropped in 2.4, but the other three are still there in 2.5 and 2.6:
>
> In case someone wonders what all those None are: they're a "flag" telling
> the import machinery that those modules don't exist (to avoid doing a
> directory scan over and over, because Python<2.7 attempts first to do a
> relative import, and only if unsuccessful attempts an absolute one)
>
>> C:\junk>\python23\python -c "import sys; print [k for (k, v) in
>> sys.modules.items() if v is None]"
>> ['encodings.encodings', 'encodings.codecs', 'encodings.exceptions',
>> 'encodings.types']
>
> In this case, somewhere inside the encodings package, there are statements
> like "import types" or "from types import ...", and Python could not find
> types.py in the package directory.
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list