-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-131918: Add _ThreadLocalSqliteConnection in dbm.sqlite #131920
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
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
IMO, yes. |
@@ -0,0 +1 @@ | |||
Fixes dbm.sqlite3 for multi-threaded use-cases by using thread-local connections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes dbm.sqlite3 for multi-threaded use-cases by using thread-local connections. | |
Make :mod:`dbm.sqlite3` thread-safe by using thread-local database connections. |
Hmm this fix doesnt really work with As in currently the close method closes connections from other threads, which would give the same error. |
Not too familiar with There should probably be a docs update to explain exactly what thread-safety guarantees this is making (and if they depend on |
Very weirdly, on my system (Fedora Linux), the sqlite3.threadsafety is set to 3 by default, but I still seem to be getting the error |
wrthread = ref(thread, thread_deleted) | ||
try: | ||
conn = sqlite3.connect(self._uri, autocommit=True, uri=True) | ||
self._conn[id(thread)] = conn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._conn[id(thread)] = conn | |
self._conn[thread.native_id] = conn |
Hmm why not using native_id?
I am a first-time contributor and I am not sure about the quality of the code at all, review comments will be appreciated :)
Will try to add a test later. Should this be back-ported to Python 3.13?