Ezio Melotti added the comment:

> Because you inserted LIBDIR before it existed, import noticed it didn't
> exist and so put None into sys.path_importer_cache[LIBDIR]

I'm not familiar with sys.path_importer_cache, but what happens if instead of 
putting None, sys.path_importer_cache[LIBDIR] is not created at all?  Will it 
check for LIBDIR next time an import is performed (possibly finding it if the 
dir has been created in the meanwhile)?
If this check happens every time, I guess it will defeat the purpose of the 
cache in case of missing dirs (especially if the dir is never created -- but 
maybe this is an uncommon case and the optimization can be removed?).

Another option could be to recheck empty dirs in the cache in case of 
ImportError, and then update the cache entry and retry the import if a new dir 
that didn't exist before is found.  This would still have an overhead, but even 
in this case the slow down might be acceptable.

If we can't find a compromise I guess we could add a note to the documentation, 
even though I'm not sure where.

FTR in the original report the user was adding a dir to sys.path before 
extracting the content of a tar file (thus creating the added dir), and adding 
the dir after the extraction fixes the problem.

I'm also attaching my version of the test case, that shows two possible "fixes" 
to the problem and is closer to the original report.

----------
Added file: http://bugs.python.org/file33615/issue20321.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20321>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to