473,387 Members | 1,904 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,387 software developers and data experts.

DB API and thread safety

Hey guys

I've been reading http://www.python.org/peps/pep-0249.html and I don't
quite get what level of thread safety I need for my DB connections.

If I call db = FOOdb::connect() at the start of my app, and then every
thread does it's own c = db.cursor() at the top, what level of thread
safety do I need to avoid threads stepping on each other? Hopefully the
answer to this question will get me oriented enough to understand the
other options :-)

Cheers

-Rob
Jan 20 '06 #1
2 1424
Robin Haswell wrote:
Hey guys

I've been reading http://www.python.org/peps/pep-0249.html and I don't
quite get what level of thread safety I need for my DB connections.

If I call db = FOOdb::connect() at the start of my app, and then every
thread does it's own c = db.cursor() at the top, what level of thread
safety do I need to avoid threads stepping on each other? Hopefully the
answer to this question will get me oriented enough to understand the
other options :-)


Assuming the cursor created in the thread is never accessed by another
thread then you need a dbapi module that supports threadsafety level 2 -
"threads may share the module and connections".

- Matt

--
__
/ \__ Matt Goodall, Pollenation Internet Ltd
\__/ \ w: http://www.pollenation.net
__/ \__/ e: ma**@pollenation.net
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.
Jan 20 '06 #2
Robin Haswell wrote:
Hey guys

I've been reading http://www.python.org/peps/pep-0249.html and I don't
quite get what level of thread safety I need for my DB connections.

If I call db = FOOdb::connect() at the start of my app, and then every
thread does it's own c = db.cursor() at the top, what level of thread
safety do I need to avoid threads stepping on each other? Hopefully the
answer to this question will get me oriented enough to understand the
other options :-)


Even if you can share the connection between threads, it will be the
rare database which can actually work concurrently on one connection.
Most drivers promising "threads may share the module and connections"
will use a lock so that only one operation is active at a time.

For maximum throughput (at the cost of using more ressources on the
database), you'd use one connection per thread. If you want to use
transactions, then it is the only way.

Daniel
Jan 20 '06 #3

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

Similar topics

4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
9
by: Alexander Fleck | last post by:
Hi, I' ve to make a software module thread safe. I know how to realize that and what' re the main topics of thread safety. But I don' t know how thread safety can be tested. I read about a test...
4
by: Warren Sirota | last post by:
Hi, I've got a method that I want to execute in a multithreaded environment (it's a specialized spider. I want to run a whole bunch of copies at low priority as a service). It works well running...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
13
by: arun.darra | last post by:
Are the following thread safe: 1. Assuming Object is any simple object Object* fn() { Object *p = new Object(); return p; } 2. is return by value thread safe?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.