class_docstr: The IPython Kernel class.
class_docstr_tok: ["The","IPython","Kernel","class","."]
docstr: Handle an apply request.
docstr_tok: ["Handle","an","apply","request","."]
code: def do_apply(self, content, bufs, msg_id, reply_metadata):
      """Handle an apply request."""
      try:
          from ipyparallel.serialize import (
              serialize_object,
              unpack_apply_message,
          )
      except ImportError:
          from .serialize import serialize_object, unpack_apply_message
  
      shell = self.shell
      assert shell is not None
      try:
          working = shell.user_ns
  
          prefix = "_" + str(msg_id).replace("-", "") + "_"
          f, args, kwargs = unpack_apply_message(
              bufs, working, copy=False
          )
  
          fname = getattr(f, "__name__", "f")
  
          fname = prefix + "f"
          argname = prefix + "args"
          kwargname = prefix + "kwargs"
          resultname = prefix + "result"
  
          ns = {
              fname: f,
              argname: args,
              kwargname: kwargs,
              resultname: None,
          }
          # print ns
          working.update(ns)
          code = f"{resultname} = {fname}(*{argname},**{kwargname})"
          try:
              exec(code, shell.user_global_ns, shell.user_ns)
              result = working.get(resultname)
          finally:
              for key in ns:
                  working.pop(key)
  
          assert self.session is not None
          result_buf = serialize_object(
              result,
              buffer_threshold=self.session.buffer_threshold,
              item_threshold=self.session.item_threshold,
          )
  
      except BaseException as e:
          # invoke IPython traceback formatting
          shell.showtraceback()
          reply_content = {
              "traceback": shell._last_traceback or [],
              "ename": str(type(e).__name__),
              "evalue": str(e),
          }
          # FIXME: deprecated piece for ipyparallel (remove in 5.0):
          e_info = dict(
              engine_uuid=self.ident,
              engine_id=self.int_id,
              method="apply",
          )
          reply_content["engine_info"] = e_info
  
          self.send_response(
              self.iopub_socket,
              "error",
              reply_content,
              ident=self._topic("error"),
          )
          self.log.info(
              "Exception in apply request:\n%s",
              "\n".join(reply_content["traceback"]),
          )
          result_buf = []
          reply_content["status"] = "error"
      else:
          reply_content = {"status": "ok"}
  
      return reply_content, result_buf
  
imports: import asyncio
  import builtins
  import getpass
  import os
  import signal
  import sys
  import threading
  import typing
  from contextlib import contextmanager
  from functools import partial
  import comm
  from IPython.core import release
  from IPython.utils.tokenutil import line_at_cursor, token_at_cursor
  from traitlets import Any, Bool, HasTraits, Instance, List, Type, observe, observe_compat
  from zmq.eventloop.zmqstream import ZMQStream
  from .comm.comm import BaseComm
  from .comm.manager import CommManager
  from .compiler import XCachingCompiler
  from .debugger import Debugger, _is_debugpy_available
  from .eventloops import _use_appnope
  from .kernelbase import Kernel
  from .kernelbase import _accepts_parameters
  from .zmqshell import ZMQInteractiveShell
label_desc: Use image node_id 21 for calling the IPythonKernel obj's underlying member method code with example usage: obj.do_apply(content, bufs, msg_id, reply_metadata) and returns: reply_content,  result_buf