db locks: wait up to 5 seconds before restarting frontend
This commit is contained in:
parent
5d0cd82f9e
commit
9ddd53fb8f
19
db.py
19
db.py
|
@ -4,7 +4,7 @@ import logging
|
||||||
from os import urandom, system
|
from os import urandom, system
|
||||||
from pylibscrypt import scrypt_mcf
|
from pylibscrypt import scrypt_mcf
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from time import sleep
|
from time import sleep, time
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -20,11 +20,18 @@ class DB(object):
|
||||||
return self.cur.execute(*args, **kwargs)
|
return self.cur.execute(*args, **kwargs)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
try:
|
start_time = time()
|
||||||
self.conn.commit()
|
while 1:
|
||||||
except sqlite3.sqlite3.OperationalError:
|
try:
|
||||||
system("rcctl restart frontend_daemon")
|
self.conn.commit()
|
||||||
self.conn.commit()
|
break
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
# another thread may be writing, give it a chance to finish
|
||||||
|
sleep(0.1)
|
||||||
|
if time() - start_time > 5:
|
||||||
|
# if it takes this long, something is wrong
|
||||||
|
system("rcctl restart frontend_daemon")
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
Loading…
Reference in a new issue