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): ...@@ -281,6 +281,7 @@ class Message(object):
handle = None handle = None
reply_to = None reply_to = None
data = '' data = ''
_unpickled = object()
router = None router = None
receiver = None receiver = None
...@@ -324,15 +325,18 @@ class Message(object): ...@@ -324,15 +325,18 @@ class Message(object):
def unpickle(self, throw=True, throw_dead=True): def unpickle(self, throw=True, throw_dead=True):
"""Deserialize `data` into an object.""" """Deserialize `data` into an object."""
_vv and IOLOG.debug('%r.unpickle()', self) _vv and IOLOG.debug('%r.unpickle()', self)
fp = cStringIO.StringIO(self.data) obj = self._unpickled
unpickler = cPickle.Unpickler(fp) if obj is Message._unpickled:
unpickler.find_global = self._find_global fp = cStringIO.StringIO(self.data)
unpickler = cPickle.Unpickler(fp)
unpickler.find_global = self._find_global
try: try:
# Must occur off the broker thread. # Must occur off the broker thread.
obj = unpickler.load() obj = unpickler.load()
except (TypeError, ValueError), ex: self._unpickled = obj
raise StreamError('invalid message: %s', ex) except (TypeError, ValueError), ex:
raise StreamError('invalid message: %s', ex)
if throw: if throw:
if obj == _DEAD and throw_dead: 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