'Replace existing connection (if there is one) and close it.'

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()
