[Distutils] indexing sys.meta_path hook?

PJ Eby pje at telecommunity.com
Sat Sep 29 00:42:29 CEST 2012


On Fri, Sep 28, 2012 at 6:27 PM, Daniel Holth <dholth at gmail.com> wrote:
> Is the new python 3.3 optimization documented anywhere? I am having trouble
> finding it.

Well, it's mentioned several places in
http://docs.python.org/dev/whatsnew/3.3.html, albeit rather obscurely.
 Most important mention is probably this:

"""The default finders used by import now utilize a cache of what is
contained within a specific directory. If you create a Python source
file or sourceless bytecode file, make sure to call
importlib.invalidate_caches() to clear out the cache for the finders
to notice the new file."""

Basically, the new system does for directories what older Pythons did
for zipfiles: read in the a directory listing on first use, and keep
it cached in memory.  Unlike zipfiles, though, there's a stat() call
done on each import to verify the directory listing isn't out of date.

Technically, you don't need to manually flush the caches every time
you put new modules in a directory, though.  The only way for the
cache to become invalid is if you try to import a module between two
changes to the same directory, there is a potential race condition on
filesystems with a highly granular filestamp type.  For example, on a
FAT filesystem, timestamps only change every two seconds, so if you
make two changes to a directory within two seconds, and an import is
attempted between those two changes, then the cache for that directory
could become stale.  A bit of info on this can be found at
http://docs.python.org/dev/library/importlib.html#importlib.machinery.FileFinder


More information about the Distutils-SIG mailing list