connection pooling manager is kind of a object responsible for create/manage connection. All connection related request should be routed through the connection pool. Pool manager will keep track on whether a connection is being used by a user or not and will allocate a free connection to serve a request for new connection. To implement the same, we need to know/check whether a connection is free or not. I need some idea, how to identify/find out the same. MySQLDB is not shipped with a connection pool manager - is there any solution available already?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
connection pooling manager is kind of a object responsible for create/manage connection. All connection related request should be routed through the connection pool. Pool manager will keep track on whether a connection is being used by a user or not and will allocate a free connection to serve a request for new connection. To implement the same, we need to know/check whether a connection is free or not. I need some idea, how to identify/find out the same. MySQLDB is not shipped with a connection pool manager - is there any solution available already?
I have a separate product for pooling objects (not just connection objects) to handle this:
http://dustman.net/andy/python/Pool
Example:
import MySQLdb
from Pool import Pool, Constructor
cp = Pool(Constructor(MySQLdb.connect, host="foo", db="blah",...))
...
db = cp.get()
# use db for awhile
cp.put(db)
del db
Hi,
I use a web server in python (Snakelets) and I have implemented your example to have a permanent connection to mysql.
In the web server I can have many webapps and each webapp generates a session for each user that opens a page.
In the webapp I have:
cp = Pool(Constructor(MySQLdb.connect, host="foo", db="blah",...))
In each webapp.session I use:
when session begins
db = webapp.cp.get()
... # use db
when session ends
webapp.cp.put(db)
del db
My question: Is there any problem have many sessions using [db = webapp.cp.get() ] ??
Thanks,
Helio Pereira
Sharky @ PTNet
PS.: Sorry my english :P
There shouldn't be a problem. If the Pool is empty and .get() is called, it just makes a new connection.