def disconnect(self):
logger.debug("<STR_LIT>")<EOL>with self.lock:<EOL><INDENT>if self._socket is None:<EOL><INDENT>if self._state != "<STR_LIT>":<EOL><INDENT>self.event(DisconnectedEvent(self._dst_addr))<EOL>self._set_state("<STR_LIT>")<EOL><DEDENT>return<EOL><DEDENT>if self._hup or not self._serializer:<EOL><INDENT>self._close()<EOL><DEDENT>else:<EOL><INDENT>self.send_stream_tail()<EOL><DEDENT><DEDENT>
Disconnect the stream gracefully.