I would like to create a :memory: database in python and access it from different threads.
Essentially something like:
class T(threading.Thread):
def run(self):
self.conn = sqlite3.connect(':memory:')
# do stuff with the database
for i in xrange(N):
T().start()
and have all the connections referring to the same database.
I am aware of passing check_same_thread=True to the connect function and sharing the
connection between threads but would like to avoid doing that if possible. Thanks for any help.
EDIT: corrected a typo. I originally said “have all the connections referring to the same thread” substituting thread for database.
Without hacking sqlite3 library itself you cannot reuse
:memory:database, because it’s guaranteed to be exclusive and private for every connection. To hack access to it, look closer atsrc/pager.cin sqlite3 distribution (not Python module distribution). Maybe, most convenient way to implement this would be make:memory:00,:memory:something,:memory:okay_haietc. aliases to address differentpPager->memDbpointers through some simple C-side mapping.