Decorator to serialize access to a callable *f*

def serialize(self, f):
        """
        Decorator to serialize access to a callable *f*
        """
        s = self.router()

        @self.spawn
        def _():
            for f, a, kw, r in s.recver:
                try:
                    r.send(f(*a, **kw))
                except Exception, e:
                    r.send(e)

        def _(*a, **kw):
            r = self.pipe()
            s.send((f, a, kw, r))
            return r.recv()

        return _