Skip to content

Commit

Permalink
fix: for issue 52 about 'sqlite3.ProgrammingError: SQLite objects cre…
Browse files Browse the repository at this point in the history
…ated in a thread can only be used in that same thread'
  • Loading branch information
ipr-sv authored and gsong committed Sep 29, 2024
1 parent 6506fe7 commit c2709b7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion epo_ops/middlewares/throttle/storages/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ class SQLite(Storage):
def __init__(self, db_path=DEFAULT_DB_PATH):
self.db_path = db_path
makedirs(os.path.dirname(db_path))
self.db = sqlite3.connect(db_path, detect_types=sqlite3.PARSE_DECLTYPES)

# Making SQLite more threadsafe, as described in https://ricardoanderegg.com/posts/python-sqlite-thread-safety/#conclusion
if sqlite3.threadsafety == 3:
check_same_thread = False
else:
check_same_thread = True

self.db = sqlite3.connect(
db_path,
detect_types=sqlite3.PARSE_DECLTYPES,
check_same_thread=check_same_thread,
)
self.db.row_factory = sqlite3.Row
self.prepare()

Expand Down

0 comments on commit c2709b7

Please sign in to comment.