本文整理汇总了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)