class_docstr: Manages a single kernel in a subprocess on this host.
  
  This version starts kernels with Popen.
class_docstr_tok: ["Manages","a","single","kernel","in","a","subprocess","on","this","host",".","This","version","starts","kernels","with","Popen","."]
docstr: Attempts to stop the kernel process cleanly.
  
  This attempts to shutdown the kernels cleanly by:
  
  1. Sending it a shutdown message over the shell channel.
  2. If that fails, the kernel is shutdown forcibly by sending it
     a signal.
  
  Parameters
  ----------
  now : bool
      Should the kernel be forcible killed *now*. This skips the
      first, nice shutdown attempt.
  restart: bool
      Will this kernel be restarted after it is shutdown. When this
      is True, connection files will not be cleaned up.
docstr_tok: ["Attempts","to","stop","the","kernel","process","cleanly",".","This","attempts","to","shutdown","the","kernels","cleanly","by",":","1",".","Sending","it","a","shutdown","message","over","the","shell","channel",".","2",".","If","that","fails",",","the","kernel","is","shutdown","forcibly","by","sending","it","a","signal",".","Parameters","--","--","--","--","--","now",":","bool","Should","the","kernel","be","forcible","killed","*","now","*",".","This","skips","the","first",",","nice","shutdown","attempt",".","restart",":","bool","Will","this","kernel","be","restarted","after","it","is","shutdown",".","When","this","is","True",",","connection","files","will","not","be","cleaned","up","."]
code: def shutdown_kernel(self, now=False, restart=False):
      """Attempts to stop the kernel process cleanly.
  
      This attempts to shutdown the kernels cleanly by:
  
      1. Sending it a shutdown message over the shell channel.
      2. If that fails, the kernel is shutdown forcibly by sending it
         a signal.
  
      Parameters
      ----------
      now : bool
          Should the kernel be forcible killed *now*. This skips the
          first, nice shutdown attempt.
      restart: bool
          Will this kernel be restarted after it is shutdown. When this
          is True, connection files will not be cleaned up.
      """
      # Stop monitoring for restarting while we shutdown.
      self.stop_restarter()
  
      if now:
          self._kill_kernel()
      else:
          self.request_shutdown(restart=restart)
          # Don't send any additional kernel kill messages immediately, to give
          # the kernel a chance to properly execute shutdown actions. Wait for at
          # most 1s, checking every 0.1s.
          self.finish_shutdown()
  
      self.cleanup(connection_file=not restart)
  
imports: from __future__ import absolute_import
  from contextlib import contextmanager
  import os
  import re
  import signal
  import sys
  import time
  import warnings
  import zmq
  from ipython_genutils.importstring import import_item
  from .localinterfaces import is_local_ip, local_ips
  from traitlets import Any, Float, Instance, Unicode, List, Bool, Type, DottedObjectName
  from jupyter_client import launch_kernel, kernelspec
  from .connect import ConnectionFileMixin
  from .managerabc import KernelManagerABC
label_desc: Use image node_id 24 for calling the KernelManager obj's underlying member method code with example usage: obj.shutdown_kernel(now, restart) without return types