code: def close(self):
          
          exc = DestructionRequested("close() called")
  
          if self.running:
              if self.sm_enabled:
                  self._xmlstream.send_xso(nonza.SMAcknowledgement(
                      counter=self._sm_inbound_ctr
                  ))
  
              yield from self._xmlstream.close_and_wait()  # does not raise
              yield from self.wait_stop()  # may raise
  
          self._closed = True
          self._xmlstream_exception = exc
          self._destroy_stream_state(self._xmlstream_exception)
          if self.sm_enabled:
              self.stop_sm()
docs: Close the stream and the underlying XML stream (if any is connected).
  
          This is essentially a way of saying "I do not want to use this stream
          anymore" (until the next call to :meth:`start`). If the stream is
          currently running, the XML stream is closed gracefully (potentially
          sending an SM ack), the worker is stopped and any Stream Management
          state is cleaned up.
  
          If an error occurs while the stream stops, the error is ignored.
  
          After the call to :meth:`close` has started, :meth:`on_failure` will
          not be emitted, even if the XML stream fails before closure has
          completed.
  
          After a call to :meth:`close`, the stream is stopped, all SM state is
          discarded and calls to :meth:`enqueue_stanza` raise a
          :class:`DestructionRequested` ``"close() called"``. Such a
          :class:`StanzaStream` can be re-started by calling :meth:`start`.
  
          .. versionchanged:: 0.8
  
             Before 0.8, an error during a call to :meth:`close` would stop the
             stream from closing completely, and the exception was re-raised. If
             SM was enabled, the state would have been kept, allowing for
             resumption and ensuring that stanzas still enqueued or
             unacknowledged would get a chance to be sent.
  
             If you want to have guarantees that all stanzas sent up to a certain
             point are sent, you should be using :meth:`send_and_wait_for_sent`
             with stream management.