Exemplo n.º 1
0
    def _write_index(self):
        assert self._lock.acquired
        with open(self.index_path + '.part', 'wb') as f:
            # Use protocol 2 for version information to ensure that
            # all Python versions supported by Nengo will be able to
            # read it in the future.
            pickle.dump((self.VERSION, pickle.HIGHEST_PROTOCOL), f, 2)
            # Use highest available protocol for index data for maximum
            # performance.
            pickle.dump(self._index, f, pickle.HIGHEST_PROTOCOL)
        try:
            replace(self.index_path + '.part', self.index_path)
        except (CalledProcessError, PermissionError):
            # It may fail when
            # another program like a virus scanner is accessing the file to be
            # moved. There is not a lot we could do about this. See
            # <https://github.com/nengo/nengo/issues/1200> for more info.
            warnings.warn(
                "The cache index could not be updated because another program "
                "blocked access to it. This is commonly caused by anti-virus "
                "software. It is safe to ignore this warning. But if you see "
                "it a lot, you might want to consider doing one of the "
                "following for the best Nengo performance:\n"
                "1. Configure your anti-virus to ignore the Nengo cache "
                "folder ('{cache_dir}').\n"
                "2. Disable the cache.\n".format(cache_dir=self.cache_dir),
                category=CacheIOWarning)

        if os.path.exists(self.legacy_path):
            os.remove(self.legacy_path)
Exemplo n.º 2
0
 def _write_index(self):
     assert self._lock.acquired
     with open(self.index_path + '.part', 'wb') as f:
         # Use protocol 2 for version information to ensure that
         # all Python versions supported by Nengo will be able to
         # read it in the future.
         pickle.dump((self.VERSION, pickle.HIGHEST_PROTOCOL), f, 2)
         # Use highest available protocol for index data for maximum
         # performance.
         pickle.dump(self._index, f, pickle.HIGHEST_PROTOCOL)
     replace(self.index_path + '.part', self.index_path)
     if os.path.exists(self.legacy_path):
         os.remove(self.legacy_path)
Exemplo n.º 3
0
 def _write_index(self):
     assert self._lock.acquired
     with open(self.index_path + '.part', 'wb') as f:
         # Use protocol 2 for version information to ensure that
         # all Python versions supported by Nengo will be able to
         # read it in the future.
         pickle.dump(
             (self.VERSION, pickle.HIGHEST_PROTOCOL),
             f, 2)
         # Use highest available protocol for index data for maximum
         # performance.
         pickle.dump(self._index, f, pickle.HIGHEST_PROTOCOL)
     replace(self.index_path + '.part', self.index_path)
     if os.path.exists(self.legacy_path):
         os.remove(self.legacy_path)
Exemplo n.º 4
0
Arquivo: cache.py Projeto: GYGit/nengo
    def sync(self):
        try:
            with self._lock:
                self._index = self._load_index()
                self._index.update(self._updates)

                for key in self._deletes:
                    del self._index[key]

                with open(self.filename + '.part', 'wb') as f:
                    pickle.dump(
                        {k: v for k, v in self._index.items()
                         if v[0] not in self._removed_files},
                        f, pickle.HIGHEST_PROTOCOL)
                replace(self.filename + '.part', self.filename)
        except TimeoutError:
            warnings.warn(
                "Decoder cache index could not acquire lock. "
                "Cache index was not synced.")

        self._updates.clear()
        self._deletes.clear()