code: def _maybe_allow_interrupt():
      """
      This manager allows to terminate a plot by sending a SIGINT. It is
      necessary because the running backend prevents Python interpreter to
      run and process signals (i.e., to raise KeyboardInterrupt exception). To
      solve this one needs to somehow wake up the interpreter and make it close
      the plot window. The implementation is taken from qt_compat, see that
      docstring for a more detailed description.
      """
      old_sigint_handler = signal.getsignal(signal.SIGINT)
      if old_sigint_handler in (None, signal.SIG_IGN, signal.SIG_DFL):
          yield
          return
  
      handler_args = None
      wsock, rsock = socket.socketpair()
      wsock.setblocking(False)
      rsock.setblocking(False)
      old_wakeup_fd = signal.set_wakeup_fd(wsock.fileno())
      _macosx.wake_on_fd_write(rsock.fileno())
  
      def handle(*args):
          nonlocal handler_args
          handler_args = args
          _macosx.stop()
  
      signal.signal(signal.SIGINT, handle)
      try:
          yield
      finally:
          wsock.close()
          rsock.close()
          signal.set_wakeup_fd(old_wakeup_fd)
          signal.signal(signal.SIGINT, old_sigint_handler)
          if handler_args is not None:
              old_sigint_handler(*handler_args)
  
imports: import contextlib
  import os
  import signal
  import socket
  import matplotlib
  from matplotlib import _api, cbook
  from matplotlib._pylab_helpers import Gcf
  from .None import _macosx
  from .backend_agg import FigureCanvasAgg
  from matplotlib.backend_bases import _Backend, FigureCanvasBase, FigureManagerBase, NavigationToolbar2, ResizeEvent, TimerBase
label_desc: Use image node_id 1 for calling a global function with example usage: _maybe_allow_interrupt() without return types