def executewait(dbhandle, statement, error=Exception, regex_error="locked",
                retries=-1, wait=5):
    cc = dbhandle.cursor()

    while 1:
        try:
            cc.execute(statement)
        except error, msg:
            if retries == 0:
                raise
            if not re.search("locked", str(msg)):
                raise
            time.sleep(wait)
            retries -= 1
            continue
        break
    return cc
repeatedly execute an SQL statement until it succeeds.
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Database.py/executewait