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


Python cPickle.PicklingError方法代码示例

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

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


示例16: 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"
            s = s[n:] 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:17,代码来源:rpc.py


示例17: update_saved_parameters

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def update_saved_parameters(training_stats, test_stack_config, args):
    if training_stats['worthy_epoch']:
        test_stack_config['best_epoch_id'] = training_stats['best_epoch_id']
        test_stack_config['validation_result'] = training_stats['validation_result']
        test_stack_config['training_result'] = training_stats['training_result']
        try:
            lstm_seqlabel_load_save_model.save_parameters_to_file(
                test_stack_config, args.saveto)
        except pickle.PicklingError as e:
            print "Suffering from Pickling Error in saving \n%s \nto %s"%(
                ' '.join(test_stack_config.keys()),
                args.saveto)

    return 
开发者ID:se4u,项目名称:neural_wfst,代码行数:16,代码来源:lstm_seqlabel_callbacks.py


示例18: pickled

# 需要导入模块: import cPickle [as 别名]
# 或者: from cPickle import PicklingError [as 别名]
def pickled(cls, obj, **kwargs):
        """
        Construct a pickled message, setting :attr:`data` to the serialization
        of `obj`, and setting remaining fields using `kwargs`.

        :returns:
            The new message.
        """
        self = cls(**kwargs)
        try:
            self.data = pickle__dumps(obj, protocol=2)
        except pickle.PicklingError:
            e = sys.exc_info()[1]
            self.data = pickle__dumps(CallError(e), protocol=2)
        return self 
开发者ID:dw,项目名称:mitogen,代码行数:17,代码来源:core.py



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