def send_apply_message(self, socket, f, args=None, kwargs=None, subheader=None, track=False,
                            ident=None):
        """construct and send an apply message via a socket.
        
        This is the principal method with which all engine execution is performed by views.
        """
                            
        assert not self._closed, "cannot use me anymore, I'm closed!"
        # defaults:
        args = args if args is not None else []
        kwargs = kwargs if kwargs is not None else {}
        subheader = subheader if subheader is not None else {}
        
        # validate arguments
        if not isinstance(f, collections.Callable):
            raise TypeError("f must be callable, not %s"%type(f))
        if not isinstance(args, (tuple, list)):
            raise TypeError("args must be tuple or list, not %s"%type(args))
        if not isinstance(kwargs, dict):
            raise TypeError("kwargs must be dict, not %s"%type(kwargs))
        if not isinstance(subheader, dict):
            raise TypeError("subheader must be dict, not %s"%type(subheader))
        
        bufs = util.pack_apply_message(f,args,kwargs)
        
        msg = self.session.send(socket, "apply_request", buffers=bufs, ident=ident,
                            subheader=subheader, track=track)
        
        msg_id = msg['msg_id']
        self.outstanding.add(msg_id)
        if ident:
            # possibly routed to a specific engine
            if isinstance(ident, list):
                ident = ident[-1]
            if ident in list(self._engines.values()):
                # save for later, in case of engine death
                self._outstanding_dict[ident].add(msg_id)
        self.history.append(msg_id)
        self.metadata[msg_id]['submitted'] = datetime.now()
        
        return msg

    #--------------------------------------------------------------------------
    # construct a View object
    #--------------------------------------------------------------------------
dataset/ETHPy150Open ipython/ipython-py3k/IPython/parallel/client/client.py/Client.send_apply_message/original