sqlitedict
sqlitedict copied to clipboard
Multi thread example
I trigger 10 thread of workers that fill the userDb, without any locking mechanisem
def worker(name, value):
userDb[name] = value
def sync():
userDb.commit()
userDb = SqliteDict('./usernames.sqlite', encode=json.dumps, decode=json.loads, autocommit=False)
I also triger sync thread every 5 minutes, is it safe to do so ?
@sionking not really sure that this is safe, @piskvorky?
I'd say yes.
More concretely, it's safe to the degree Sqlite itself supports these operations and workload. All SqliteDict does is serialize the requests from multiple threads into a single queue, executing them one after the other. It adds thread safety, not extra performance.
@piskvorky Im guessing the order of the queue is somewhat unpredictable? If I have 10 threads all writing to the same key (and say some of them happen to write at the exact same time) I don't know the order of which they will be executed?
Correct.