On Sat, Feb 14, 2009 at 4:15 PM, Jack Orenstein <j...@geophile.com> wrote:

>
> I'm trying to understand how Django 1.0 handles connections. This is
> from the django docs, on the subject of raw SQL:
>
>     from django.db import connection
>     cursor = connection.cursor()
>     cursor.execute("select ...")
>     row = cursor.fetchone()
>
> If I have a Django app running lots of requests, then how are
> connections handled? Is connection the same in each request, even
> requests running concurrently? That can't possibly be the case,
> (could it)? So does each request get its own? When are connections
> closed? When closed are they really closed, or just returned to a
> pool? Can the pool be configured, (e.g. to set the postgres
> search_path)?
>
> Sorry to ask such basic questions, but I've been unable to find this
> information documented.
>
> Jack Orenstein
>
>
> >
>
A quick disclaimer, all of this is AFAIK and to the best of my memory:

The connection object in django.db is a thread local object, meaning that
each thread get's it's own one, and whenever you access that object you get
the one for the current thread(it may actually mean that all the attributes
on the object are local to that thread, I don't completely remember, the
effect is the same anyway).  This basically means each request has it's own
connection to the DB since you can't have multiple simultaneous requests in
the same thread.  There is a signal handler that closes this connection to
the DB at the end of each request.  There is no connection pool, when a new
connection is opened it is really created to the db, and when it's closed it
really is closed.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

Reply via email to