Nikolaus Rath <nikol...@rath.org> wrote: >>> Is BEGIN ... COMMIT sufficient for that? >> >> No. Transaction is also maintained per connection. Starting a >> transaction would prevent other connections from making concurrent >> changes, but wouldn't block other threads using the same connection. > > Actually it seems to do exactly that: > >> >> def thread1(): >> cur = conn.cursor() >> cur.execute("BEGIN") >> print "Thread 1 in transaction" >> time.sleep(5) >> print "Thread 1 finished." >> >> def thread2(): >> cur = conn.cursor() >> time.sleep(2) >> cur.execute("BEGIN") >> print "Thread 2 in transaction" >> time.sleep(5) >> print "Thread 2 finished."
What you see is the effect that Nuno Lucas pointed out: if you try to execute BEGIN while there's an open transaction, you'll get an error. It doesn't matter whether the nested BEGIN is executed on the same or different thread. This behavior doesn't mean that starting a transaction blocks out other threads - they can happily execute any statements (which would then become part of the open transaction), just not BEGIN. So yes, you can use BEGIN statement as a test to see whether a transaction is open on a connection. I must admit I haven't thought of that. See also sqlite3_get_autocommit. Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users