当前位置: 首页>>代码示例>>Python>>正文


Python cPickle.PicklingError方法代码示例

本文整理汇总了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 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:19,代码来源:cmodule.py

示例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 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:23,代码来源:cmodule.py

示例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 
开发者ID:terrapower,项目名称:armi,代码行数:21,代码来源:mpiActions.py

示例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) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:17,代码来源:ops.py

示例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)) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:10,代码来源:squeues.py

示例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) 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:9,代码来源:test_run.py

示例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) 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:9,代码来源:test_run.py

示例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) 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:10,代码来源:test_run.py

示例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 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:44,代码来源:cmodule.py


注:本文中的six.moves.cPickle.PicklingError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。