python - Concurrent writing with sqlite3 -
this question has answer here:
- sqlite3 concurrent access 4 answers
i'm using sqlite3
python module write results batch jobs common .db
file. chose sqlite because multiple processes may try write @ same time, , understand sqlite should handel well. i'm unsure of happens when multiple processes finish , try write @ same time. if several processes this
conn = connect('test.db') conn: v in xrange(10): tup = (str(v), v) conn.execute("insert sometable values (?,?)", tup)
execute @ once, throw exception? wait politely other processes write? there better way this?
the sqlite
library lock database per process when writing database , each process wait lock released turn.
the database doesn't need written until commit time however. using connection context manager (good!) commit takes place after loop has completed , insert
statements have been executed.
if database has uniqueness constraints in place, may commit fails because 1 process has added rows process conflicts with.
Comments
Post a Comment