本文整理匯總了Python中DBUtils.PooledDB.PooledDB方法的典型用法代碼示例。如果您正苦於以下問題:Python PooledDB.PooledDB方法的具體用法?Python PooledDB.PooledDB怎麽用?Python PooledDB.PooledDB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DBUtils.PooledDB
的用法示例。
在下文中一共展示了PooledDB.PooledDB方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init
# 需要導入模塊: from DBUtils import PooledDB [as 別名]
# 或者: from DBUtils.PooledDB import PooledDB [as 別名]
def init(config):
try:
global __connection_pool
__connection_pool = PooledDB(
creator=MySQLdb,
mincached=1,
maxcached=20,
host=config.db_host,
port=config.db_port,
user=config.db_user,
passwd=config.db_pass,
db=config.db_database,
use_unicode=False,
charset="utf8",
cursorclass=DictCursor)
return True
except Exception as e:
logger.exception(e,"Mysql數據庫初始化失敗:host=%s,user=%s,pass=%s,db=%s",config.db_host,config.db_user,config.db_pass,config.db_database)
return False
示例2: _connect_with_pooling
# 需要導入模塊: from DBUtils import PooledDB [as 別名]
# 或者: from DBUtils.PooledDB import PooledDB [as 別名]
def _connect_with_pooling(self, keywords):
def get_pooled_db():
from DBUtils import PooledDB
# In DBUtils 0.9.3, `dbapi` argument is renamed as `creator`
# see Bug#122112
if PooledDB.__version__.split('.') < '0.9.3'.split('.'):
return PooledDB.PooledDB(dbapi=self.db_module, **keywords)
else:
return PooledDB.PooledDB(creator=self.db_module, **keywords)
if getattr(self, '_pooleddb', None) is None:
self._pooleddb = get_pooled_db()
return self._pooleddb.connection()
示例3: _connect_with_pooling
# 需要導入模塊: from DBUtils import PooledDB [as 別名]
# 或者: from DBUtils.PooledDB import PooledDB [as 別名]
def _connect_with_pooling(self, keywords):
def get_pooled_db():
from DBUtils import PooledDB
# In DBUtils 0.9.3, `dbapi` argument is renamed as `creator`
# see Bug#122112
if PooledDB.__version__.split('.') < '0.9.3'.split('.'):
return PooledDB.PooledDB(dbapi=self.db_module, **keywords)
else:
return PooledDB.PooledDB(creator=self.db_module, **keywords)
if getattr(self, '_pooleddb', None) is None:
self._pooleddb = get_pooled_db()
return self._pooleddb.connection()
示例4: __init__
# 需要導入模塊: from DBUtils import PooledDB [as 別名]
# 或者: from DBUtils.PooledDB import PooledDB [as 別名]
def __init__(self, pool, shared_con):
"""Create a pooled shared connection.
pool: the corresponding PooledDB instance
con: the underlying SharedDBConnection
"""
# basic initialization to make finalizer work
self._con = None
# proper initialization of the connection
con = shared_con.con
if not con.threadsafety() > 1:
raise NotSupportedError("Database connection is not thread-safe.")
self._pool = pool
self._shared_con = shared_con
self._con = con
示例5: __init__
# 需要導入模塊: from DBUtils import PooledDB [as 別名]
# 或者: from DBUtils.PooledDB import PooledDB [as 別名]
def __init__(self):
connkwargs = {
'host': Config.MYSQL_CONFIG['HOST'],
'user': Config.MYSQL_CONFIG['USER'],
'port': Config.MYSQL_CONFIG['PORT'],
'passwd': Config.MYSQL_CONFIG['PASSWORD'],
'db': Config.MYSQL_CONFIG['NAME'],
'charset': "utf8"
}
self._pool = PooledDB(MySQLdb, mincached=0, maxcached=10, maxshared=10, maxusage=10000, **connkwargs)