SQlite WAL-mode in python. Concurrency with one writer and one reader -
i'm trying share sqlite3 database between 1 writer process, , 1 reader process. however, not work, , seems me nothing being written in example.db.
reader.py
import sqlite3 time import sleep conn = sqlite3.connect('example.db', isolation_level=none) c = conn.cursor() while true: c.execute("select * statistics") try: print '**' print c.fetchone() except: pass sleep(3)
writer.py
import sqlite3 time import sleep import os if os.path.exists('example.db'): os.remove('example.db') conn = sqlite3.connect('example.db', isolation_level=none) c = conn.cursor() c.execute('pragma journal_mode=wal') print c.fetchone() c.execute("create table statistics (stat1 real, stat2 real)") stat1 = 0 stat2 = 0.0 while true: stat1 += 1 stat2 += 0.1 cmd = "insert statistics values (%d,%f)" % (stat1, stat2) print cmd c.execute(cmd) #conn.commit() c.execute("pragma wal_checkpoint=full") sleep(0.25)
i run writer.py in background process, , run reader.py. shows:
** (1.0, 0.1) ** (1.0, 0.1) ** (1.0, 0.1)
(...)
what correct (and best) way set framework 1 reader , 1 writer?
what expect? select first row of table. , same row. "pragma"-statements have no visible effects here.
Comments
Post a Comment