code: def stop(self):
          
          if not self.running:
              return
          self._logger.debug("sending stop signal to task")
          self._task.cancel()
docs: Send a signal to the main broker task to terminate. You have to check
          :attr:`running` and possibly wait for it to become :data:`False` ---
          the task takes at least one loop through the event loop to terminate.
  
          It is guarenteed that the task will not attempt to send stanzas over
          the existing `xmlstream` after a call to :meth:`stop` has been made.
  
          It is legal to call :meth:`stop` even if the task is already
          stopped. It is a no-op in that case.