Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > DB API and thread safety

Reply
Thread Tools

DB API and thread safety

 
 
Robin Haswell
Guest
Posts: n/a
 
      01-20-2006
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
 
Reply With Quote
 
 
 
 
Matt Goodall
Guest
Posts: n/a
 
      01-20-2006
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: http://www.velocityreviews.com/forums/(E-Mail Removed)
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.
 
Reply With Quote
 
 
 
 
Daniel Dittmar
Guest
Posts: n/a
 
      01-20-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Java Reflection API with Java Annotation Types for Thread Safety pek Java 2 10-23-2007 03:00 PM
ASP.net and thread safety =?Utf-8?B?U2ltbw==?= ASP .Net 4 01-13-2006 05:26 PM
Thread-safety and Singleton methods =?Utf-8?B?RGlmZmlkZW50?= ASP .Net 1 01-13-2005 06:07 PM
Re: Re: Is Python/C api thread safety enough? Donnie Leen Python 2 11-25-2004 07:04 AM
Is Python/C api thread safety enough? Casper Python 1 11-20-2004 05:12 PM



Advertisments