Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: for issue 52 about 'sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread' #117

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading