piskvorky / sqlitedict

Persistent dict, backed by sqlite3 and pickle, multithread-safe.
Apache License 2.0
1.17k stars 131 forks source link

bug while trying to insert or read records. [code inside] #140

Open ashuezy opened 3 years ago

ashuezy commented 3 years ago

image

sql_operation(0, oneId, twoId, threeId, fc)

def sql_operation(w, oneId, twoId, threeId, fc):
    global code_folder
    fc2=0
    try:
        if w==0:
            try:
                mydict = SqliteDict(code_folder+'core.sqlite', autocommit=True)
                uid = str(oneId)+"_"+str(twoId)+"_"+str(threeId)
                mydict[uid] = fc
            except Exception as e0:
                logger.error(e0)
            finally:
                mydict.close()
        elif w==1:
            try:
                logger.info('Acquiring Lock by fetchRow')
                lock.acquire(timeout=5)
                logger.info('Lock Taken by fetchRow')
                mydict = SqliteDict(code_folder+'core.sqlite', autocommit=True)
                uid = str(oneId)+"_"+str(twoId)+"_"+str(threeId)
                fc2 = mydict[uid]
            except Exception as e1:
                logger.error(e1)
            finally:
                mydict.close()
                logger.info('Releasing Lock by fetchRow')
                lock.release()
                logger.info('Lock Released by fetchRow')
    except Exception as e:
        logger.error(e)
    return fc2