diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -19,6 +19,7 @@ work. One should use importlib as the pu # Bootstrap-related code ###################################################### +import time CASE_INSENSITIVE_PLATFORMS = 'win', 'cygwin', 'darwin' @@ -763,20 +764,24 @@ class _FileFinder: self._path_mtime = -1 self._path_cache = set() self._cache_refresh = 0 + self._last_time = 0.0 def find_module(self, fullname): """Try to find a loader for the specified module.""" tail_module = fullname.rpartition('.')[2] if _relax_case(): tail_module = tail_module.lower() - try: - mtime = _os.stat(self.path).st_mtime - except OSError: - mtime = -1 - if mtime != self._path_mtime or _cache_refresh != self._cache_refresh: - self._fill_cache() - self._path_mtime = mtime - self._cache_refresh = _cache_refresh + now = time.time() + if now > self._last_time + 1: + self._last_time = now + try: + mtime = _os.stat(self.path).st_mtime + except OSError: + mtime = -1 + if mtime != self._path_mtime or _cache_refresh != self._cache_refresh: + self._fill_cache() + self._path_mtime = mtime + self._cache_refresh = _cache_refresh cache = self._path_cache if tail_module in cache: base_path = _path_join(self.path, tail_module)