Basic question:
 I have 1 app with multiple processes and threads.  Each thread
and/or process may end up trying to do something to the database at the
same time.  What is the solution to threading?  How do web frameworks
solve it?  Is there some inherent design in databases and/or SQLAlchemy
that makes this not a actual problem?   What do I do if I have 2
separate apps?  3?

I know there has got to be a simple answer to this (after all, every web app 
has to deal with it), but I can't find anywhere that explains it....

Details:
Ok, so let's say I am developing an app with the potential for many threads and 
processes.  The problem is what do I do when each of those threads and 
processes need to access the database in different ways?  read data, change 
data, etc...

The SQLAlchemy documentation says that Sessions are not thread safe and talk 
about using my own locking mechanisms.  However, if I recall correctly, many 
web frameworks don't even deal with threading issues, yet allow interaction 
with the database across many threads (http server responses).

The PostgreSQL documention on the subject didn't help much: 
http://www.postgresql.org/docs/8.4/static/mvcc.html except to show that I 
really don't want to have anything to do with managing the complexities of 
multiple connections to a database.
Pylons docs were equally as vague as the SQLAlchemy docs: essentially that some 
vague thing is not thread safe in some vague way.

Ok, so here's what I can gather.  SQLAlchemy is setup like so:

1 Session => 1 DB Connection (from connection pool) => Database

* If I setup 2 sessions, that means I will have 2 connections to the database, 
meaning the database is the one that will handle threading conflicts per what 
is described here: http://www.postgresql.org/docs/8.4/static/mvcc.html

I really don't like relying on that.
However, the SQLAlchemy docs suggest making many small Sessions for short 
interaction with the database.  The problem is if I have many threads/processes 
accessing the DB simultaneously (through separate sessions\connections), then I 
could get into threading problems working with the database, right?

Is the solution to use one single session for the entire application (the 
application consisting of many processes and threads) and making all my 
processes communicate with this single session when it needs to do database 
stuff?

Somehow, I have my doubts that it how it should be done -- and even the 
SQLAlchemy docs say otherwise (although again, very vague about what it is 
talking about).


So, I have 1 app with multiple processes and threads.  Each thread and/or 
process may end up trying to do something to the database at the same time.  
What is the solution to threading?  How do web frameworks solve it?  Is there 
some inherent design in databases and/or SQLAlchemy that makes this not a 
actual problem?   What do I do if I have 2 separate apps?  3?
                                          
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
http://clk.atdmt.com/GBL/go/171222985/direct/01/

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to