made connections thread safe

This commit is contained in:
iou1name 2018-03-25 14:26:48 -04:00
parent 83889b2941
commit c2ee013975

7
db.py
View File

@ -4,6 +4,7 @@ The bot's database connection class.
"""
import os
import sqlite3
import threading
class FulviaDB(object):
"""
@ -13,6 +14,7 @@ class FulviaDB(object):
def __init__(self, config):
path = config.core.db_filename
self.filename = path
self.db_lock = threading.Lock()
def connect(self):
"""Return a raw database connection object."""
@ -26,5 +28,8 @@ class FulviaDB(object):
called per PEP 249.
"""
with self.connect() as conn:
self.db_lock.acquire()
cur = conn.cursor()
return cur.execute(*args, **kwargs)
res = cur.execute(*args, **kwargs)
self.db_lock.release()
return res