Python six.moves.cPickle.PicklingError() Examples
The following are 14
code examples of six.moves.cPickle.PicklingError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six.moves.cPickle
, or try the search function
.
Example #1
Source File: cmodule.py From D-VAE with MIT License | 6 votes |
def save_pkl(self): """ Dump this object into its `key_pkl` file. May raise a cPickle.PicklingError if such an exception is raised at pickle time (in which case a warning is also displayed). """ # Note that writing in binary mode is important under Windows. try: with open(self.key_pkl, 'wb') as f: pickle.dump(self, f, protocol=pickle.HIGHEST_PROTOCOL) except pickle.PicklingError: _logger.warning("Cache leak due to unpickle-able key data %s", self.keys) os.remove(self.key_pkl) raise
Example #2
Source File: cmodule.py From D-VAE with MIT License | 6 votes |
def _get_from_hash(self, module_hash, key, keep_lock=False): if module_hash in self.module_hash_to_key_data: key_data = self.module_hash_to_key_data[module_hash] module = self._get_from_key(None, key_data) with compilelock.lock_ctx(keep_lock=keep_lock): try: key_data.add_key(key, save_pkl=bool(key[0])) key_broken = False except pickle.PicklingError: key_data.remove_key(key) key_broken = True # We need the lock while we check in case of parallel # process that could be changing the file at the same # time. if (key[0] and not key_broken and self.check_for_broken_eq): self.check_key(key, key_data.key_pkl) self._update_mappings(key, key_data, module.__file__, check_in_keys=not key_broken) return module else: return None
Example #3
Source File: cmodule.py From attention-lvcsr with MIT License | 6 votes |
def save_pkl(self): """ Dump this object into its `key_pkl` file. May raise a cPickle.PicklingError if such an exception is raised at pickle time (in which case a warning is also displayed). """ # Note that writing in binary mode is important under Windows. try: with open(self.key_pkl, 'wb') as f: pickle.dump(self, f, protocol=pickle.HIGHEST_PROTOCOL) except pickle.PicklingError: _logger.warning("Cache leak due to unpickle-able key data %s", self.keys) os.remove(self.key_pkl) raise
Example #4
Source File: cmodule.py From attention-lvcsr with MIT License | 6 votes |
def _get_from_hash(self, module_hash, key, keep_lock=False): if module_hash in self.module_hash_to_key_data: key_data = self.module_hash_to_key_data[module_hash] module = self._get_from_key(None, key_data) with compilelock.lock_ctx(keep_lock=keep_lock): try: key_data.add_key(key, save_pkl=bool(key[0])) key_broken = False except pickle.PicklingError: key_data.remove_key(key) key_broken = True # We need the lock while we check in case of parallel # process that could be changing the file at the same # time. if (key[0] and not key_broken and self.check_for_broken_eq): self.check_key(key, key_data.key_pkl) self._update_mappings(key, key_data, module.__file__, check_in_keys=not key_broken) return module else: return None
Example #5
Source File: mpiActions.py From armi with Apache License 2.0 | 6 votes |
def _mpiOperationHelper(self, obj, mpiFunction): """ Strips off the operator, reactor, cs from the mpiAction before """ if obj is None or obj is self: # prevent sending o, r, and cs, they should be handled appropriately by the other nodes # reattach with finally obj = self o, r, cs = self.o, self.r, self.cs self.o = self.r = self.cs = None try: return mpiFunction(obj, root=0) except (cPickle.PicklingError) as error: runLog.error("Failed to {} {}.".format(mpiFunction.__name__, obj)) runLog.error(error) raise finally: if obj is self: self.o, self.r, self.cs = o, r, cs
Example #6
Source File: ops.py From D-VAE with MIT License | 5 votes |
def __reduce__(self): mod = self.__fn.__module__ name = self.__fn.__name__ try: obj = load_back(mod, name) except (ImportError, KeyError, AttributeError): raise pickle.PicklingError( "Can't pickle as_op(), not found as %s.%s" % (mod, name)) else: if obj is not self: raise pickle.PicklingError( "Can't pickle as_op(), not the object " "at %s.%s" % (mod, name)) return load_back, (mod, name)
Example #7
Source File: ops.py From attention-lvcsr with MIT License | 5 votes |
def __reduce__(self): mod = self.__fn.__module__ name = self.__fn.__name__ try: obj = load_back(mod, name) except (ImportError, KeyError, AttributeError): raise pickle.PicklingError( "Can't pickle as_op(), not found as %s.%s" % (mod, name)) else: if obj is not self: raise pickle.PicklingError( "Can't pickle as_op(), not the object " "at %s.%s" % (mod, name)) return load_back, (mod, name)
Example #8
Source File: squeues.py From learn_python3_spider with MIT License | 5 votes |
def _pickle_serialize(obj): try: return pickle.dumps(obj, protocol=2) # Python <= 3.4 raises pickle.PicklingError here while # 3.5 <= Python < 3.6 raises AttributeError and # Python >= 3.6 raises TypeError except (pickle.PicklingError, AttributeError, TypeError) as e: raise ValueError(str(e))
Example #9
Source File: squeues.py From learn_python3_spider with MIT License | 5 votes |
def _pickle_serialize(obj): try: return pickle.dumps(obj, protocol=2) # Python <= 3.4 raises pickle.PicklingError here while # 3.5 <= Python < 3.6 raises AttributeError and # Python >= 3.6 raises TypeError except (pickle.PicklingError, AttributeError, TypeError) as e: raise ValueError(str(e))
Example #10
Source File: test_run.py From pytest-plugins with MIT License | 5 votes |
def test_run_in_runbound_method_on_unpickleable_class(): class C(object): def fn(self, *args, **kwargs): return self, args, kwargs with patch('pytest_shutil.run.execnet'): with pytest.raises(cPickle.PicklingError): run.run_in_subprocess(C().fn, python='sentinel.python')(ARG, kw=KW)
Example #11
Source File: test_run.py From pytest-plugins with MIT License | 5 votes |
def test_run_in_rununbound_method_on_unpickleable_class(): class C(object): def fn(self, *args, **kwargs): return self, args, kwargs with patch('pytest_shutil.run.execnet'): with pytest.raises(cPickle.PicklingError): run.run_in_subprocess(C.fn, python='sentinel.python')(C(), ARG, kw=KW)
Example #12
Source File: test_run.py From pytest-plugins with MIT License | 5 votes |
def test_run_in_runclassmethod_on_unpickleable_class(): class C(object): @classmethod def fn(cls, *args, **kwargs): return cls, args, kwargs with patch('pytest_shutil.run.execnet'): with pytest.raises(cPickle.PicklingError): run.run_in_subprocess(C.fn, python='sentinel.python')(ARG, kw=KW)
Example #13
Source File: cmodule.py From D-VAE with MIT License | 4 votes |
def _add_to_cache(self, module, key, module_hash): """ This function expects the compile lock to be held. """ name = module.__file__ _logger.debug("Adding module to cache %s %s", key, name) # Changing the hash of the key is not allowed during # compilation. That is the only cause found that makes # the following assert fail. assert key not in self.entry_from_key location = os.path.dirname(name) key_pkl = os.path.join(location, 'key.pkl') assert not os.path.exists(key_pkl) key_data = KeyData( keys=set([key]), module_hash=module_hash, key_pkl=key_pkl, entry=name) key_broken = False if key[0]: try: key_data.save_pkl() except pickle.PicklingError: key_broken = True key_data.remove_key(key) key_data.save_pkl() if not key_broken and self.check_for_broken_eq: self.check_key(key, key_pkl) self.loaded_key_pkl.add(key_pkl) elif config.cmodule.warn_no_version: key_flat = flatten(key) ops = [k for k in key_flat if isinstance(k, theano.Op)] _logger.warning("not all the" " following op(s) implement" " c_code_cache_version(). This makes them" " recompiled for each process." + str(ops)) self._update_mappings(key, key_data, module.__file__, not key_broken) return key_data
Example #14
Source File: cmodule.py From attention-lvcsr with MIT License | 4 votes |
def _add_to_cache(self, module, key, module_hash): """ This function expects the compile lock to be held. """ name = module.__file__ _logger.debug("Adding module to cache %s %s", key, name) # Changing the hash of the key is not allowed during # compilation. That is the only cause found that makes # the following assert fail. assert key not in self.entry_from_key location = os.path.dirname(name) key_pkl = os.path.join(location, 'key.pkl') assert not os.path.exists(key_pkl) key_data = KeyData( keys=set([key]), module_hash=module_hash, key_pkl=key_pkl, entry=name) key_broken = False if key[0]: try: key_data.save_pkl() except pickle.PicklingError: key_broken = True key_data.remove_key(key) key_data.save_pkl() if not key_broken and self.check_for_broken_eq: self.check_key(key, key_pkl) self.loaded_key_pkl.add(key_pkl) elif config.cmodule.warn_no_version: key_flat = flatten(key) ops = [k for k in key_flat if isinstance(k, theano.Op)] _logger.warning("not all the" " following op(s) implement" " c_code_cache_version(). This makes them" " recompiled for each process." + str(ops)) self._update_mappings(key, key_data, module.__file__, not key_broken) return key_data