473,419 Members | 3,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

[pysqlite] How do I use pysqlite in a multi-threading env.?

In my wxPython-app a part of it gathers data, when a button is pressed, and
stores it into a db.

The GUI part should display the stuff being stored in the db.

When both parts work on the same connection, I get "SQL statements in
progress errors". Seems ok to me, you can't do that.

So, next step: Both parts get a separate connection. Now I get "Database
locked" errors. Hmm, yes, it's GUI stuff after all, being all in the same
thread.

So, next step: I put the data gathering part into a real thread, that's
started, wehn the "Scan" button is pressed. This way the "Database locked"-
errors should got away. But now I get "SQLite objects created in a thread
can only be used in that same thread.The object was created in thread id
3576 and this is thread id 1040". Hmm, true, I want to display db content,
that was stored by an other thread. But that's what multi-threading
capabilities are for!

I must be missing something here. Anyway, I'm a bit lost now, really. So,
how are you doing such stuff with pysqlite?

Kind regards
Franz GEIGER


Jul 19 '05 #1
2 2048
On Fri, May 20, 2005 at 08:42:54AM +0200, F. GEIGER wrote:
In my wxPython-app a part of it gathers data, when a button is pressed, and
stores it into a db.

The GUI part should display the stuff being stored in the db.

When both parts work on the same connection, I get "SQL statements in
progress errors". Seems ok to me, you can't do that.
You get that error message with which pysqlite call?
So, next step: Both parts get a separate connection. Now I get "Database
locked" errors. Hmm, yes, it's GUI stuff after all, being all in the same
thread.
One connection did not commit() or rollback() within the default
timeout (5 seconds). SQLite is not a good solution if you need
long transactions, because other SQLite connections are blocked, then.
So, next step: I put the data gathering part into a real thread, that's
started, wehn the "Scan" button is pressed. This way the "Database locked"-
errors should got away. But now I get "SQLite objects created in a thread
can only be used in that same thread.The object was created in thread id
3576 and this is thread id 1040". Hmm, true, I want to display db content,
that was stored by an other thread. But that's what multi-threading
capabilities are for!
Yes, but pysqlite's threadsafety level is 1, that means you cannot share
a connection object among multiple threads. In order to ensure that and
to avoid that you get random and unexplainable crashes, I implemented
this warning.
I must be missing something here. Anyway, I'm a bit lost now, really. So,
how are you doing such stuff with pysqlite?


Use multiple connections and commit/rollback early.

HTH,

-- Gerhard
--
Gerhard Häring - gh@ghaering.de - Python, web & database development

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFCjZBDdIO4ozGCH14RAjnnAJ9mc+xjol3Ya8AyhQKByb 6EuKmrRwCfRsjQ
aH9eY/8sZk2VKt5ufoZwVX0=
=X36A
-----END PGP SIGNATURE-----

Jul 19 '05 #2

"Gerhard Haering" <gh@ghaering.de> schrieb im Newsbeitrag
news:ma*************************************@pytho n.org...

I've completely rewritten the db handling stuff, which formerly did too much
behind the scenes (explicit is better than implicit...). Now everything
looks much better. No unexpected errors and - most important - locking works
as expected. I have no idea yet, what went wrong with the former (probably
more pythonic) solution. It always did it with MySQL as backend.

Anyway, I'm quite happy now, that I can work on a db, that is incorporated
into the app itself.

Thanks for your help, Gerhard! And, sorry for the troubles...

Kind regards
Franz GEIGER
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Martin Maney | last post by:
Apologies if this isn't news here - I've been too busy this last week or so for even skimming the traffic here, in part because I've been messing around with Ubuntu's preview release on a spare...
1
by: F. GEIGER | last post by:
I've troubles to let my app take off using pysqlite. What I wonder most for now is that "pysqlite2.dbapi2.OperationalError: cannot commit transaction - SQL statements in progress" when I do this:...
6
by: Rob Cowie | last post by:
Hi all, I'm having difficulty installing pysqlite 2.1.3 on Mac OS X 10.4.4 There are some notes on the pysqlite wiki regarding modification of the setup.py script and I've followed them to no...
1
by: DurumDara | last post by:
Hi ! I have this code in my program. Before this I use APSW, but that project's connection object doesn't have close method... .... crs.execute(*'''create table files (*f_id integer not null...
1
by: Michael Husmann | last post by:
After upgrading from pysqlite 2.0.5 to pysqlite 2.3.0 writing into a sqlite database increases memory consumption heavily. A similar program with Ruby and sqlite-ruby 1.1.0 does not affect memory...
1
by: Thomas | last post by:
Hi there! Installing TurboGears out-of-the-box (egg-based) on Windows doesn't work because I can't compile the extensions needed for the required pysqlite (also egg- based): Installed...
14
by: Nader Emami | last post by:
I have installed "TurboGears" and I would install 'pysqlite' also. I am a user on a Linux machine. If I try to install the 'pysqlite' with 'easy_install' tool I get the next error message. The...
5
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 pysqlite 2.5.0 released ======================= I'm pleased to announce the availability of pysqlite 2.5.0. This is a release with major new...
4
by: Tilman Kispersky | last post by:
I am trying to install sqlite for use with python on cygwin. I have installed the sqlite packages from cygwin (that is libsqlite3-devel and libsqlite3_0). When attempting to easy_install pysqlite...
15
by: Kurda Yon | last post by:
Hi, I try to "build" and "install" pysqlite? After I type "python setup.py build" I get a lot of error messages? The first error is "src/ connection.h:33:21: error: sqlite3.h: No such file or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.