code: def cancel():
      
      cancel = threading.Event()
  
      def cancel_execution(signum, frame):
          signame = SIGNAL_NAMES.get(signum, signum)
          logger.info("Signal %s received, quitting "
                      "(this can take some time)...", signame)
          cancel.set()
  
      signal.signal(signal.SIGINT, cancel_execution)
      signal.signal(signal.SIGTERM, cancel_execution)
      return cancel
docs: Returns a threading.Event() that will get set when SIGTERM, or
      SIGINT are triggered. This can be used to cancel execution of threads.