Re: Threads, introspection, sharing of :memory: databases
Gerhard Häring <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Skip Montanaro wrote:
> 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? [...]
No, each :memory: database is separate from all others, even when created
in the same process. If you need to share the same database among different
threads, I'd recommend using file-based SQLite databases instead. If you
want to start with an empty database, just like :memory: ones, you can just
delete the file before opening the first connection.
Sharing connections among threads is/was not really supported with
pysqlite. Even with pysqlite's parameter check_same_thread=False. But AFAIC
disabling the check should now be ok now with SQLite 3.5.0 or later.
- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHKPLfdIO4ozGCH14RAscrAJ9FqlOpeXRt8GXgkFZTBYFdfc1ZvgCglFZh
Zr+0KB18qIvkFsJdCv3rKRI=
=Xi8j
-----END PGP SIGNATURE-----