importthreading,os,timefromlogilab.common.testlibimportTestCase,unittest_mainfromlogilab.common.dbimportget_connectionclassSQLiteTC(TestCase):sqlite_file='_extlite_test.sqlite'defsetUp(self):cnx1=get_connection('sqlite',database=self.sqlite_file)cu=cnx1.cursor()cu.execute('CREATE TABLE toto(name integer);')cnx1.commit()cnx1.close()deftearDown(self):try:os.remove(self.sqlite_file)except:passdeftest(self):lock=threading.Lock()defrun_thread():cnx2=get_connection('sqlite',database=self.sqlite_file)lock.acquire()cu=cnx2.cursor()cu.execute('SELECT name FROM toto')self.failIf(cu.fetchall())cnx2.commit()lock.release()time.sleep(0.1)lock.acquire()cu.execute('SELECT name FROM toto')self.failUnless(cu.fetchall())lock.release()cnx1=get_connection('sqlite',database=self.sqlite_file)lock.acquire()thread=threading.Thread(target=run_thread)thread.start()cu=cnx1.cursor()cu.execute('SELECT name FROM toto')lock.release()time.sleep(0.1)cnx1.commit()lock.acquire()cu.execute("INSERT INTO toto(name) VALUES ('toto')")cnx1.commit()lock.release()if__name__=='__main__':unittest_main()