def _set_new_connection(self, conn):
        """
        Replace existing connection (if there is one) and close it.
        """
        with self._lock:
            old = self._connection
            self._connection = conn

        if old:
            log.debug("[control connection] Closing old connection %r, replacing with %r", old, conn)
            old.close()
def _set_new_connection ( self , conn ) : with self . _lock : old = self . _connection self . _connection = conn if old : log . debug ( "[control connection] Closing old connection %r, replacing with %r" , old , conn ) old . close ( )
Replace existing connection (if there is one) and close it.