gh-131918: Add _ThreadLocalSqliteConnection in dbm.sqlite#131920
gh-131918: Add _ThreadLocalSqliteConnection in dbm.sqlite#131920meghprkh wants to merge 5 commits intopython:mainfrom
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.
| 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.
| 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?