當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。