eventlet.db_pool gives a DBApi 2 connection objectI m trying to figure out
if Webpy db can be made to send db stuff using this connection

Please let me know if you know how to do this

Thanks a lot


http://wiki.secondlife.com/wiki/Eventlet/Documentation#Database_Access
Database Access

Most of the existing DB API implementations, especially MySQLdb, block in C.
Therefore, eventlet's monkey patching of the socket module is not enough;
since the database adapter does not use the python socket methods, calling
them will block the entire process. Thus, any usage of them must call these
blocking methods in the thread pool. To facilitate this, eventlet's DB pool
module provides some convenient objects.

*eventlet.db_pool.DatabaseConnector(module, credentials, min_size=0,
max_size=4, conn_pool=None, *args, **kwargs)*

Create an object which knows how to connect to databases and return a pool
from which one can get a database connection object. module is a module
which has a "connect" function which returns a DBApi 2 Connection object.
credentials is a dictionary of host names to username/password. The min_size
and max_size arguments control the maximum number of simultaneous
connections allowed to each database. The conn_pool argument can be either
SaranwrappedConnectionPool which will use one python process per database
connection, or TpooledConnectionPool which will use eventlet.tpool and
threads instead of processes. Thread pool is the default.

import MySQLdb
import eventlet.db_pool

connector = eventlet.db_pool.DatabaseConnector(MySQLdb,
{'mydb.example.com': {'user': 'foo', 'password': 'bar'}})

pool = connector.get('mydb.example.com', 'databasename')

conn = pool.get()
curs = conn.cursor()

curs.execute('select * from foo')
results = curs.fetchall()

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to