code: def halt(self):
          
          if self.is_closed:
              # We were asked to stop because the connection is already gone.
              # There's no graceful way to stop because we can't acknowledge
              # messages in the middle of being processed.
              _std_log.info("Disconnect requested, but AMQP connection already gone")
              self._channel = None
              return
  
          _std_log.info(
              "Waiting for %d consumer(s) to finish processing before halting",
              len(self._consumers),
          )
          pending_cancels = []
          for c in list(self._consumers.values()):
              pending_cancels.append(c.cancel())
          yield defer.gatherResults(pending_cancels)
          _std_log.info("Finished canceling %d consumers", len(self._consumers))
  
          try:
              yield self.close()
          except pika.exceptions.ConnectionWrongStateError:
              pass  # Already closing, not a problem since that's what we want.
          self._consumers = {}
          self._channel = None
docs: Signal to consumers they should stop after finishing any messages
          currently being processed, then close the connection.
  
          Returns:
              defer.Deferred: fired when all consumers have successfully stopped
              and the connection is closed.