docstr: dispatch shell requests
docstr_tok: ["dispatch","shell","requests"]
code: def dispatch_shell(self, stream, msg):
      """dispatch shell requests"""
      # flush control requests first
      if self.control_stream:
          self.control_stream.flush()
  
      idents, msg = self.session.feed_identities(msg, copy=False)
      try:
          msg = self.session.deserialize(msg, content=True, copy=False)
      except:
          self.log.error("Invalid Message", exc_info=True)
          return
  
      # Set the parent message for side effects.
      self.set_parent(idents, msg)
      self._publish_status("busy")
  
      msg_type = msg["header"]["msg_type"]
  
      # Print some info about this message and leave a '--->' marker, so it's
      # easier to trace visually the message chain when debugging.  Each
      # handler prints its message at the end.
      self.log.debug("\n*** MESSAGE TYPE:%s***", msg_type)
      self.log.debug("   Content: %s\n   --->\n   ", msg["content"])
  
      if not self.should_handle(stream, msg, idents):
          return
  
      handler = self.shell_handlers.get(msg_type, None)
      if handler is None:
          self.log.warning("Unknown message type: %r", msg_type)
      else:
          self.log.debug("%s: %s", msg_type, msg)
          self.pre_handler_hook()
          try:
              handler(stream, idents, msg)
          except Exception:
              self.log.error(
                  "Exception in message handler:", exc_info=True
              )
          finally:
              self.post_handler_hook()
  
      sys.stdout.flush()
      sys.stderr.flush()
      self._publish_status("idle")
  
imports: from __future__ import print_function
  import sys
  import time
  import logging
  import uuid
  from datetime import datetime
  from signal import signal, default_int_handler, SIGINT
  import zmq
  from tornado import ioloop
  from zmq.eventloop.zmqstream import ZMQStream
  from traitlets.config.configurable import SingletonConfigurable
  from IPython.core.error import StdinNotImplementedError
  from ipython_genutils import py3compat
  from ipython_genutils.py3compat import unicode_type, string_types
  from ipykernel.jsonutil import json_clean
  from traitlets import Any, Instance, Float, Dict, List, Set, Integer, Unicode, Bool, observe, default
  from jupyter_client.session import Session
  from ._version import kernel_protocol_version
label_desc: Use image node_id 6 for calling the Kernel obj's underlying member method code with example usage: obj.dispatch_shell(stream, msg) without return types