sqlite3, memory db and multithreading

Aahz aahz at pythoncraft.com
Thu Mar 18 23:06:00 CET 2010

In article <hnt81m$fsi$1 at news.task.gda.pl>,
=?UTF-8?B?a3LDs2xld25h?=  <królewna 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 probably need to serialize access to the database through one thread.
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer

More information about the Python-list mailing list