Commit 671f7532 authored by David Wilson's avatar David Wilson

core: cache result of unpickling message.

parent 5b87d10a
......@@ -281,6 +281,7 @@ class Message(object):
handle = None
reply_to = None
data = ''
_unpickled = object()
router = None
receiver = None
......@@ -324,15 +325,18 @@ class Message(object):
def unpickle(self, throw=True, throw_dead=True):
"""Deserialize `data` into an object."""
_vv and IOLOG.debug('%r.unpickle()', self)
fp = cStringIO.StringIO(self.data)
unpickler = cPickle.Unpickler(fp)
unpickler.find_global = self._find_global
obj = self._unpickled
if obj is Message._unpickled:
fp = cStringIO.StringIO(self.data)
unpickler = cPickle.Unpickler(fp)
unpickler.find_global = self._find_global
try:
# Must occur off the broker thread.
obj = unpickler.load()
except (TypeError, ValueError), ex:
raise StreamError('invalid message: %s', ex)
try:
# Must occur off the broker thread.
obj = unpickler.load()
self._unpickled = obj
except (TypeError, ValueError), ex:
raise StreamError('invalid message: %s', ex)
if throw:
if obj == _DEAD and throw_dead:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment