From c2ee013975a0f6c90520cd225d7d30209089c45e Mon Sep 17 00:00:00 2001 From: iou1name Date: Sun, 25 Mar 2018 14:26:48 -0400 Subject: [PATCH] made connections thread safe --- db.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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