On 5/28/05, Brian Beck <exogen@...> wrote:
> As far as I can tell, sqlhub doesn't have much documentation currently.
> Where does getConnection() get the connection from, exactly? Where
> should I tell each thread what its connection is?
I sent a message earlier today that is relevant here (subject:
ConnectionHub and autoconnect or something like that).
The source for ConnectionHub is very simple. The basic idea is that
keeps thread local variables (using threading.local) for the
connections. When you call getConnection(), it looks to see if you
have one set up for that thread. If not, it looks to see if you have a
process connection. If not, if fails.
The onus is on you to ensure that it has a connection to play with.
When you create a thread that will be doing database access, you can
open a connection and then call sqlhub.threadConnection =3D <your
connection>, and you're all set.
You can also use the technique that I mentioned in my earlier
message... if there is no connection for the thread, open one and hang
on to it.
ConnectionHub may not be terribly well documented yet, but it's in
dbconnection.py and is quite easy to follow.