Thread: [SQLObject] Multithread application using a shared SQLite object
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Leandro S. <lea...@gm...> - 2007-11-29 17:49:49
|
Hi, I had a single thread application that access one sqlite database via SQLObject. Recently I change it and now I need to have multiples threads accessing this database. I'm experimenting my new approach and in some cases I get an exception from SQLObject, like this: "OperationalError: database is locked" Is there any way to have multiple threads accessing SQLite database? for instance, just one thread write to the database and the others have just read-only access. If it is possible, this solve my problem. Thanks, Leandro. |
From: Leandro S. <lea...@gm...> - 2007-11-29 17:50:38
|
ERRATA: in subject I meant "SQLite database via SQLObject" Thanks, Leandro. 2007/11/29, Leandro Sales <lea...@gm...>: > Hi, > I had a single thread application that access one sqlite database > via SQLObject. Recently I change it and now I need to have multiples > threads accessing this database. I'm experimenting my new approach and > in some cases I get an exception from SQLObject, like this: > "OperationalError: database is locked" > Is there any way to have multiple threads accessing SQLite database? > for instance, just one thread write to the database and the others > have just read-only access. If it is possible, this solve my problem. > > Thanks, > Leandro. > --=20 Leandro Melo de Sales. Pervasive and Embedded Computing Laboratory BRisa and E-Phone Projects Manager Network Admin @ http://embedded.ufcg.edu.br/indexen.html +55 83 3310-1404 (extension 208) O especialista =E9 algu=E9m que conhece sempre mais sobre cada vez menos e termina por saber tudo sobre nada! |
From: Simon C. <hod...@gm...> - 2007-11-29 22:18:55
|
On 2007/11/29, Leandro Sales <lea...@gm...> wrote: > I had a single thread application that access one sqlite database > via SQLObject. Recently I change it and now I need to have multiples > threads accessing this database. I'm experimenting my new approach and > in some cases I get an exception from SQLObject, like this: > "OperationalError: database is locked" > Is there any way to have multiple threads accessing SQLite database? > for instance, just one thread write to the database and the others > have just read-only access. If it is possible, this solve my problem. I've encountered this problem with SQLite while not using SQLObject. As far as I can tell, the short answer to your question is no. The long answer is that SQLite claims to be thread-safe [1] but as far as I can tell their definition of thread-safe is "will not corrupt your database" and not "operations will always suceed". Reading from the database in multiple threads should work if you are careful and your version of SQLite is recent enough, but if you read the answer to question 5 from the FAQ [2], it appears that writing to the database from multiple threads or proccesses will not succeed. I believe it is attempting multiple simultaneous write operations which raised the "database is locked" error. Given that you have a single application I would guess it would be possible to manually acquire a Python threading lock and wait for the database to free up if you are sufficiently careful. [1] http://www.sqlite.org/faq.html#q6 [2] http://www.sqlite.org/faq.html#q5 Schiavo Simon |
From: Leandro S. <lea...@gm...> - 2007-11-29 22:21:34
|
Well, I just have one thread writing and the others reading, is still it not possible? Leandro. 2007/11/29, Simon Cross <hod...@gm...>: > On 2007/11/29, Leandro Sales <lea...@gm...> wrote: > > I had a single thread application that access one sqlite database > > via SQLObject. Recently I change it and now I need to have multiples > > threads accessing this database. I'm experimenting my new approach and > > in some cases I get an exception from SQLObject, like this: > > "OperationalError: database is locked" > > Is there any way to have multiple threads accessing SQLite database? > > for instance, just one thread write to the database and the others > > have just read-only access. If it is possible, this solve my problem. > > I've encountered this problem with SQLite while not using SQLObject. > As far as I can tell, the short answer to your question is no. > > The long answer is that SQLite claims to be thread-safe [1] but as far > as I can tell their definition of thread-safe is "will not corrupt > your database" and not "operations will always suceed". Reading from > the database in multiple threads should work if you are careful and > your version of SQLite is recent enough, but if you read the answer to > question 5 from the FAQ [2], it appears that writing to the database > from multiple threads or proccesses will not succeed. I believe it is > attempting multiple simultaneous write operations which raised the > "database is locked" error. > > Given that you have a single application I would guess it would be > possible to manually acquire a Python threading lock and wait for the > database to free up if you are sufficiently careful. > > [1] http://www.sqlite.org/faq.html#q6 > [2] http://www.sqlite.org/faq.html#q5 > > Schiavo > Simon > --=20 Leandro Melo de Sales. Pervasive and Embedded Computing Laboratory BRisa and E-Phone Projects Manager Network Admin @ http://embedded.ufcg.edu.br/indexen.html +55 83 3310-1404 (extension 208) O especialista =E9 algu=E9m que conhece sempre mais sobre cada vez menos e termina por saber tudo sobre nada! |