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


Python cPickle.PicklingError方法代码示例

本文整理汇总了Python中cPickle.PicklingError方法的典型用法代码示例。如果您正苦于以下问题:Python cPickle.PicklingError方法的具体用法?Python cPickle.PicklingError怎么用?Python cPickle.PicklingError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cPickle的用法示例。


在下文中一共展示了cPickle.PicklingError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: put

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def put(self, o):
        """Encode object ``o`` and write it to the pipe.
        Block gevent-cooperatively until all data is written. The default
        encoder is ``pickle.dumps``.

        :arg o: a Python object that is encodable with the encoder of choice.

        Raises:
            - :exc:`GIPCError`
            - :exc:`GIPCClosed`
            - :exc:`pickle.PicklingError`

        """
        self._validate()
        with self._lock:
            bindata = self._encoder(o)
            self._write(struct.pack("!i", len(bindata)) + bindata) 
开发者ID:jgehrcke,项目名称:gipc,代码行数:19,代码来源:gipc.py

示例2: test_reduce_bad_iterator

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def test_reduce_bad_iterator(self):
        # Issue4176: crash when 4th and 5th items of __reduce__()
        # are not iterators
        class C(object):
            def __reduce__(self):
                # 4th item is not an iterator
                return list, (), None, [], None
        class D(object):
            def __reduce__(self):
                # 5th item is not an iterator
                return dict, (), None, None, []

        # Protocol 0 in Python implementation is less strict and also accepts
        # iterables.
        for proto in protocols:
            try:
                self.dumps(C(), proto)
            except (AttributeError, pickle.PicklingError, cPickle.PicklingError):
                pass
            try:
                self.dumps(D(), proto)
            except (AttributeError, pickle.PicklingError, cPickle.PicklingError):
                pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:pickletester.py

示例3: putmessage

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def putmessage(self, message):
        self.debug("putmessage:%d:" % message[0])
        try:
            s = pickle.dumps(message)
        except pickle.PicklingError:
            print >>sys.__stderr__, "Cannot pickle:", repr(message)
            raise
        s = struct.pack("<i", len(s)) + s
        while len(s) > 0:
            try:
                r, w, x = select.select([], [self.sock], [])
                n = self.sock.send(s[:BUFSIZE])
            except (AttributeError, TypeError):
                raise IOError, "socket no longer exists"
            except socket.error:
                raise
            else:
                s = s[n:] 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:20,代码来源:rpc.py

示例4: sendFuture

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def sendFuture(self, future):
        """Send a Future to be executed remotely."""
        future = copy.copy(future)
        future.greenlet = None
        future.children = {}

        try:
            if shared.getConst(hash(future.callable), timeout=0):
                # Enforce name reference passing if already shared
                future.callable = SharedElementEncapsulation(hash(future.callable))
            self.socket.send_multipart([
                TASK,
                pickle.dumps(future.id, pickle.HIGHEST_PROTOCOL),
                pickle.dumps(future, pickle.HIGHEST_PROTOCOL),
            ])
        except (pickle.PicklingError, TypeError) as e:
            # If element not picklable, pickle its name
            # TODO: use its fully qualified name
            scoop.logger.warn("Pickling Error: {0}".format(e))
            future.callable = hash(future.callable)
            self.socket.send_multipart([
                TASK,
                pickle.dumps(future.id, pickle.HIGHEST_PROTOCOL),
                pickle.dumps(future, pickle.HIGHEST_PROTOCOL),
            ]) 
开发者ID:soravux,项目名称:scoop,代码行数:27,代码来源:scoopzmq.py

示例5: sendFuture

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def sendFuture(self, future):
        """Send a Future to be executed remotely."""
        try:
            if shared.getConst(hash(future.callable),
                               timeout=0):
                # Enforce name reference passing if already shared
                future.callable = SharedElementEncapsulation(hash(future.callable))
            self.socket.send_multipart([b"TASK",
                                        pickle.dumps(future,
                                                     pickle.HIGHEST_PROTOCOL)])
        except pickle.PicklingError as e:
            # If element not picklable, pickle its name
            # TODO: use its fully qualified name
            scoop.logger.warn("Pickling Error: {0}".format(e))
            previousCallable = future.callable
            future.callable = hash(future.callable)
            self.socket.send_multipart([b"TASK",
                                        pickle.dumps(future,
                                                     pickle.HIGHEST_PROTOCOL)])
            future.callable = previousCallable 
开发者ID:soravux,项目名称:scoop,代码行数:22,代码来源:scooptcp.py

示例6: _object_contents

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def _object_contents(obj):
    """Return the signature contents of any Python object.

    We have to handle the case where object contains a code object
    since it can be pickled directly.
    """
    try:
        # Test if obj is a method.
        return _function_contents(obj.__func__)

    except AttributeError:
        try:
            # Test if obj is a callable object.
            return _function_contents(obj.__call__.__func__)

        except AttributeError:
            try:
                # Test if obj is a code object.
                return _code_contents(obj)

            except AttributeError:
                try:
                    # Test if obj is a function object.
                    return _function_contents(obj)

                except AttributeError:
                    # Should be a pickable Python object.
                    try:
                        return cPickle.dumps(obj)
                    except (cPickle.PicklingError, TypeError):
                        # This is weird, but it seems that nested classes
                        # are unpickable. The Python docs say it should
                        # always be a PicklingError, but some Python
                        # versions seem to return TypeError.  Just do
                        # the best we can.
                        return str(obj) 
开发者ID:coin3d,项目名称:pivy,代码行数:38,代码来源:Action.py

示例7: test_handledByPickleModule

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def test_handledByPickleModule(self):
        """
        Handling L{pickle.PicklingError} handles
        L{_UniversalPicklingError}.
        """
        self.assertRaises(pickle.PicklingError,
                          self.raise_UniversalPicklingError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_styles.py

示例8: test_handledBycPickleModule

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def test_handledBycPickleModule(self):
        """
        Handling L{cPickle.PicklingError} handles
        L{_UniversalPicklingError}.
        """
        try:
            import cPickle
        except ImportError:
            raise unittest.SkipTest("cPickle not available.")
        else:
            self.assertRaises(cPickle.PicklingError,
                              self.raise_UniversalPicklingError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_styles.py

示例9: test_lambdaRaisesPicklingError

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def test_lambdaRaisesPicklingError(self):
        """
        Pickling a C{lambda} function ought to raise a L{pickle.PicklingError}.
        """
        self.assertRaises(pickle.PicklingError, pickle.dumps, lambdaExample)
        try:
            import cPickle
        except:
            pass
        else:
            self.assertRaises(cPickle.PicklingError, cPickle.dumps,
                              lambdaExample) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_styles.py

示例10: dumps

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def dumps(self, obj):
        try:
            return cloudpickle.dumps(obj, 2)
        except pickle.PickleError:
            raise
        except Exception as e:
            emsg = _exception_message(e)
            if "'i' format requires" in emsg:
                msg = "Object too large to serialize: %s" % emsg
            else:
                msg = "Could not serialize object: %s: %s" % (e.__class__.__name__, emsg)
            cloudpickle.print_exec(sys.stderr)
            raise pickle.PicklingError(msg) 
开发者ID:runawayhorse001,项目名称:LearningApacheSpark,代码行数:15,代码来源:serializers.py

示例11: dump

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def dump(self, value, f):
        try:
            pickle.dump(value, f, 2)
        except pickle.PickleError:
            raise
        except Exception as e:
            msg = "Could not serialize broadcast: %s: %s" \
                  % (e.__class__.__name__, _exception_message(e))
            print_exec(sys.stderr)
            raise pickle.PicklingError(msg)
        f.close() 
开发者ID:runawayhorse001,项目名称:LearningApacheSpark,代码行数:13,代码来源:broadcast.py

示例12: dump_model

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def dump_model(self, model_file="model_%s.pkl" % strftime("%Y%m%d_%H%M")):
        """ Pickle trained model """
        if self.debug:
            logging.info("Dumping model to %s" % model_file)
        with open(model_file, "wb") as f_pkl:
            try:
                pickle.dump(self.pipeline_1, f_pkl, pickle.HIGHEST_PROTOCOL)
                pickle.dump(self.pipeline_2, f_pkl, pickle.HIGHEST_PROTOCOL)
                self.model_name = model_file
            except pickle.PicklingError as e_pkl:
                print str(e_pkl) + ": continuing without dumping." 
开发者ID:clips,项目名称:news-audit,代码行数:13,代码来源:bias_classifier.py

示例13: dump_model

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def dump_model(self, model_file="model_%s.pkl" % strftime("%Y%m%d_%H%M")):
        """ Pickle trained model """
        if self.debug:
            logging.info("Dumping model to %s" % model_file)
        with open(model_file, "wb") as f_pkl:
            try:
                pickle.dump(self.pipeline, f_pkl, pickle.HIGHEST_PROTOCOL)
                self.model_name = model_file
            except pickle.PicklingError as e_pkl:
                print str(e_pkl) + ": continuing without dumping." 
开发者ID:clips,项目名称:news-audit,代码行数:12,代码来源:SensationalismClassifier.py

示例14: __reduce__

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def __reduce__(self):
        if self.fail:
            raise PicklingError("Error in pickle")
        else:
            return id, (42, ) 
开发者ID:joblib,项目名称:loky,代码行数:7,代码来源:test_reusable_executor.py

示例15: test_queue_full_deadlock

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def test_queue_full_deadlock(self):
        executor = get_reusable_executor(max_workers=1)
        fs_fail = [executor.submit(do_nothing, ErrorAtPickle(True))
                   for i in range(100)]
        fs = [executor.submit(do_nothing, ErrorAtPickle(False))
              for i in range(100)]
        with pytest.raises(PicklingError):
            fs_fail[99].result()
        assert fs[99].result() 
开发者ID:joblib,项目名称:loky,代码行数:11,代码来源:test_reusable_executor.py


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