def _on_msg(self, msg):
        """Handle messages from the front-end"""
        data = msg['content']['data']

        # If the message is a call invoke, run the function and send
        # the results.
        if 'callback' in data:
            guid = data['callback']
            callback = callback_registry[guid]
            args = data['arguments']
            args = [self.deserialize(a) for a in args]
            index = data['index']

            results = callback(*args)
            return self.serialize(self._send('return', index=index, results=results))

        # The message is not a call invoke, it must be an object
        # that is a response to a Python request.
        else:
            index = data['index']
            immutable = data['immutable']
            value = data['value']
            if index in self._callbacks:
                self._callbacks[index].resolve({
                    'immutable': immutable,
                    'value': value
                })
                del self._callbacks[index]
def _on_msg ( self , msg ) : data = msg [ 'content' ] [ 'data' ] if 'callback' in data : guid = data [ 'callback' ] callback = callback_registry [ guid ] args = data [ 'arguments' ] args = [ self . deserialize ( a ) for a in args ] index = data [ 'index' ] results = callback ( * args ) return self . serialize ( self . _send ( 'return' , index = index , results = results ) ) else : index = data [ 'index' ] immutable = data [ 'immutable' ] value = data [ 'value' ] if index in self . _callbacks : self . _callbacks [ index ] . resolve ( { 'immutable' : immutable , 'value' : value } ) del self . _callbacks [ index ]
Handle messages from the front-end