sqlite3, memory db and multithreading

Expo daniele.esposti at gmail.com
Fri Mar 19 03:20:32 EDT 2010


On Mar 18, 1:58 pm, królewna <kr le... at ee.pl> wrote:
> The problem is simple: I have multiple threads within one program. At
> least 2 threads have to have access to in-memory sqlite database. It is
> not possible to pass sqlite objects to those threads because an
> exception is rised:
>
> ProgrammingError: SQLite objects created in a thread can only be used in
> that same thread.The object was created in thread id -1219066176 and
> this is thread id -1224475792
>
> Is there any EASY way to use this in-memory db in many threads? Creating
> another connection is not a solution as it creates completely new db
> instead of connecting to the existing one.
>

You can put the SQLite database into a Singleton class and use a
semaphore to serialize the access to methods which writes to the
database.



More information about the Python-list mailing list