From e7c4736b780fae8dd6d98798de45a0973cdab434 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 16 Aug 2016 13:59:06 +0100 Subject: [PATCH] Better handle unpicklable objects. --- econtext/core.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/econtext/core.py b/econtext/core.py index 70833c6b..a0ae9433 100644 --- a/econtext/core.py +++ b/econtext/core.py @@ -402,7 +402,11 @@ class Stream(BasicStream): def _enqueue(self, handle, obj): IOLOG.debug('%r._enqueue(%r, %r)', self, handle, obj) - encoded = cPickle.dumps((handle, obj), protocol=2) + try: + encoded = cPickle.dumps((handle, obj), protocol=2) + except cPickle.PicklingError, e: + encoded = cPickle.dumps((handle, CallError(e)), protocol=2) + msg = struct.pack('>L', len(encoded)) + encoded self._whmac.update(msg) self._output_buf += self._whmac.digest() + msg