本文整理匯總了Python中six.moves.cPickle.PicklingError方法的典型用法代碼示例。如果您正苦於以下問題:Python cPickle.PicklingError方法的具體用法?Python cPickle.PicklingError怎麽用?Python cPickle.PicklingError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six.moves.cPickle
的用法示例。
在下文中一共展示了cPickle.PicklingError方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save_pkl
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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
示例2: _get_from_hash
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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
示例3: _mpiOperationHelper
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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
示例4: __reduce__
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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)
示例5: _pickle_serialize
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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))
示例6: test_run_in_runbound_method_on_unpickleable_class
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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)
示例7: test_run_in_rununbound_method_on_unpickleable_class
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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)
示例8: test_run_in_runclassmethod_on_unpickleable_class
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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)
示例9: _add_to_cache
# 需要導入模塊: from six.moves import cPickle [as 別名]
# 或者: from six.moves.cPickle import PicklingError [as 別名]
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