Threads, introspection, sharing of :memory: databases

Skip Montanaro <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
I'm using pysqlite in some multi-threaded software.  All I need is the
:memory:database.  If I understand the errors I've received thusfar, I can't
share a single connection in multiple threads.  Accordingly, I need

    self.connection = sqlite3.connect(":memory:")

in each thread.  If I execute that in different threads is one ini-memory
database created which is shared across all threads?

Let's assume that's the case.  I then need to create tables, e.g.:

    cursor = self.connection.cursor()
    cursor.execute("create table foo ...")
    cursor.commit()

Executing that multiple times in the same thread yields an OperationalError.
Is there not some way of introspecting the database for its tables, or do I
just have to catch the exception?

Thanks,

Skip Montanaro
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.