diff options
author | Brett Cannon <brett@python.org> | 2012-02-27 23:15:42 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-02-27 23:15:42 (GMT) |
commit | b46a1793a787747d59e735e12471b3a309aa51da (patch) | |
tree | 61eacabf46212791ef3fa96f44c95c9593c8607d /Lib/importlib/_bootstrap.py | |
parent | 9a4d7ddb6c09af03953840ff8a2c1215fc6742a7 (diff) | |
download | cpython-b46a1793a787747d59e735e12471b3a309aa51da.zip cpython-b46a1793a787747d59e735e12471b3a309aa51da.tar.gz cpython-b46a1793a787747d59e735e12471b3a309aa51da.tar.bz2 |
Update importlib.invalidate_caches() to be more general.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index b3fda71..faa5830 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -160,17 +160,6 @@ code_type = type(_wrap.__code__) # Finder/loader utility code ################################################## -_cache_refresh = 0 - -def invalidate_caches(): - """Invalidate importlib's internal caches. - - Calling this function may be needed if some modules are installed while - your program is running and you expect the program to notice the changes. - """ - global _cache_refresh - _cache_refresh += 1 - def set_package(fxn): """Set __package__ on the returned module.""" @@ -768,7 +757,10 @@ class _FileFinder: self._path_mtime = -1 self._path_cache = set() self._relaxed_path_cache = set() - self._cache_refresh = 0 + + def invalidate_caches(self): + """Invalidate the directory mtime.""" + self._path_mtime = -1 def find_module(self, fullname): """Try to find a loader for the specified module.""" @@ -777,10 +769,9 @@ class _FileFinder: mtime = _os.stat(self.path).st_mtime except OSError: mtime = -1 - if mtime != self._path_mtime or _cache_refresh != self._cache_refresh: + if mtime != self._path_mtime: self._fill_cache() self._path_mtime = mtime - self._cache_refresh = _cache_refresh # tail_module keeps the original casing, for __file__ and friends if _relax_case(): cache = self._relaxed_path_cache |