This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients berdario, brett.cannon, eric.snow, ezio.melotti, ncoghlan
Date 2014-01-22.11:43:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1390391034.07.0.842945011463.issue20321@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2014-01-22 11:43:54ezio.melottisetrecipients: + ezio.melotti, brett.cannon, ncoghlan, eric.snow, berdario
2014-01-22 11:43:54ezio.melottisetmessageid: <1390391034.07.0.842945011463.issue20321@psf.upfronthosting.co.za>
2014-01-22 11:43:54ezio.melottilinkissue20321 messages
2014-01-22 11:43:53ezio.melotticreate