code: def loop_cocoa(kernel):
      """Start the kernel, coordinating with the Cocoa CFRunLoop event loop
      via the matplotlib MacOSX backend.
      """
      from ._eventloop_macos import mainloop, stop
  
      real_excepthook = sys.excepthook
  
      def handle_int(etype, value, tb):
          """don't let KeyboardInterrupts look like crashes"""
          # wake the eventloop when we get a signal
          stop()
          if etype is KeyboardInterrupt:
              print(
                  "KeyboardInterrupt caught in CFRunLoop",
                  file=sys.__stdout__,
              )
          else:
              real_excepthook(etype, value, tb)
  
      while not kernel.shell.exit_now:
          try:
              # double nested try/except, to properly catch KeyboardInterrupt
              # due to pyzmq Issue #130
              try:
                  # don't let interrupts during mainloop invoke crash_handler:
                  sys.excepthook = handle_int
                  mainloop(kernel._poll_interval)
                  if kernel.shell_stream.flush(limit=1):
                      # events to process, return control to kernel
                      return
              except BaseException:
                  raise
          except KeyboardInterrupt:
              # Ctrl-C shouldn't crash the kernel
              print(
                  "KeyboardInterrupt caught in kernel",
                  file=sys.__stdout__,
              )
          finally:
              # ensure excepthook is restored
              sys.excepthook = real_excepthook
  
imports: import os
  import platform
  import sys
  from functools import partial
  import zmq
  from packaging.version import Version
  from traitlets.config.application import Application
label_desc: Use image node_id 15 for calling a global function with example usage: loop_cocoa(kernel) without return types