@@ -90,20 +90,22 @@ def flush(self, forced=False):
9090 self ._write_cache .clear ()
9191 self ._cache_lock .release ()
9292
93- self . beginTransaction ()
94- for hash_ , value in items :
95- while True :
96- try :
93+ try :
94+ self . beginTransaction ()
95+ for hash_ , value in items :
96+ while True :
9797 try :
98- self .cursor .execute ("INSERT INTO storage VALUES (?, ?)" , (hash_ , value ,))
99- except sqlite3 .IntegrityError :
100- self .cursor .execute ("UPDATE storage SET value=? WHERE id=?" , (value , hash_ ,))
101- except sqlite3 .OperationalError , ex :
102- if not 'locked' in ex .message :
103- raise
104- else :
105- break
106- self .endTransaction ()
98+ try :
99+ self .cursor .execute ("INSERT INTO storage VALUES (?, ?)" , (hash_ , value ,))
100+ except sqlite3 .IntegrityError :
101+ self .cursor .execute ("UPDATE storage SET value=? WHERE id=?" , (value , hash_ ,))
102+ except sqlite3 .OperationalError , ex :
103+ if not 'locked' in ex .message :
104+ raise
105+ else :
106+ break
107+ finally :
108+ self .endTransaction ()
107109
108110 def beginTransaction (self ):
109111 self .cursor .execute ('BEGIN TRANSACTION' )
0 commit comments