diff --git a/db.py b/db.py index c1e3c4f..0253edd 100755 --- a/db.py +++ b/db.py @@ -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