本文整理汇总了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)
示例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
示例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:]
示例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),
])
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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."
示例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."
示例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, )
示例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()