當前位置: 首頁>>代碼示例>>Python>>正文


Python PooledDB.PooledDB方法代碼示例

本文整理匯總了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 
開發者ID:newsettle,項目名稱:ns4_chatbot,代碼行數:22,代碼來源:db_helper.py

示例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() 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:18,代碼來源:basedb.py

示例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() 
開發者ID:joxeankoret,項目名稱:nightmare,代碼行數:18,代碼來源:db.py

示例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 
開發者ID:WebwareForPython,項目名稱:DBUtils,代碼行數:18,代碼來源:PooledDB.py

示例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) 
開發者ID:LanceLRQ,項目名稱:wejudge,代碼行數:12,代碼來源:base.py


注:本文中的DBUtils.PooledDB.PooledDB方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。