本文整理汇总了Python中sqlalchemy.pool.manage函数的典型用法代码示例。如果您正苦于以下问题:Python manage函数的具体用法?Python manage怎么用?Python manage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了manage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testbadargs
def testbadargs(self):
manager = pool.manage(mock_dbapi)
try:
connection = manager.connect(None)
except:
pass
示例2: __init__
def __init__(self, host, database, user, password, debug=False):
self.host = host
self.database = database
# 用于判断是否打印sql
self.debug = debug
args = {'database': database}
if user is not None:
args['user'] = user
if password is not None:
args['password'] = password
pair = host.split(':')
if len(pair) == 2:
args['host'] = pair[0]
args['port'] = int(pair[1])
else:
args['host'] = pair[0]
args['port'] = 3388
self.args = args
self._db = None
# 单位为秒
self._db_operation_timeout = 300
# 连接池
self.conn_pool = pool.manage(
MySQLdb, pool_size=20, max_overflow=40, timeout=self._db_operation_timeout, recycle=1800)
self.reconnection()
示例3: testnonthreadlocalmanager
def testnonthreadlocalmanager(self):
manager = pool.manage(mock_dbapi, use_threadlocal=False)
connection = manager.connect("foo.db")
connection2 = manager.connect("foo.db")
self.assert_(connection.cursor() is not None)
self.assert_(connection is not connection2)
示例4: test_non_thread_local_manager
def test_non_thread_local_manager(self):
manager = pool.manage(MockDBAPI(), use_threadlocal=False)
connection = manager.connect('foo.db')
connection2 = manager.connect('foo.db')
self.assert_(connection.cursor() is not None)
self.assert_(connection is not connection2)
示例5: patch_postgresql
def patch_postgresql():
try:
from django.db.backends.postgresql_psycopg2 import base as pgsql_base
except (ImproperlyConfigured, ImportError) as e:
return
if not hasattr(pgsql_base, "_Database"):
pgsql_base._Database = pgsql_base.Database
pgsql_base.Database = manage(pgsql_base._Database, **POOL_SETTINGS)
示例6: patch_oracle
def patch_oracle():
try:
from django.db.backends.oracle import base as oracle_base
except (ImproperlyConfigured, ImportError) as e:
return
if not hasattr(oracle_base, "_Database"):
oracle_base._Database = oracle_base.Database
oracle_base.Database = manage(oracle_base._Database, **POOL_SETTINGS)
示例7: patch_sqlite3
def patch_sqlite3():
try:
from django.db.backends.sqlite3 import base as sqlite3_base
except (ImproperlyConfigured, ImportError) as e:
return
if not hasattr(sqlite3_base, "_Database"):
sqlite3_base._Database = sqlite3_base.Database
sqlite3_base.Database = manage(sqlite3_base._Database, **POOL_SETTINGS)
示例8: testmanager
def testmanager(self):
manager = pool.manage(mock_dbapi, use_threadlocal=True)
connection = manager.connect("foo.db")
connection2 = manager.connect("foo.db")
connection3 = manager.connect("bar.db")
self.assert_(connection.cursor() is not None)
self.assert_(connection is connection2)
self.assert_(connection2 is not connection3)
示例9: testnonthreadlocalmanager
def testnonthreadlocalmanager(self):
manager = pool.manage(mock_dbapi, use_threadlocal = False)
connection = manager.connect('foo.db')
connection2 = manager.connect('foo.db')
self.echo( "connection " + repr(connection))
self.assert_(connection.cursor() is not None)
self.assert_(connection is not connection2)
示例10: testmanager
def testmanager(self):
manager = pool.manage(mock_dbapi, use_threadlocal=True)
connection = manager.connect('foo.db')
connection2 = manager.connect('foo.db')
connection3 = manager.connect('bar.db')
print "connection " + repr(connection)
self.assert_(connection.cursor() is not None)
self.assert_(connection is connection2)
self.assert_(connection2 is not connection3)
示例11: get_pool
def get_pool():
"Creates one and only one pool using the configured settings."
global MYSQLPOOL
if MYSQLPOOL is None:
backend = getattr(settings, 'MYSQLPOOL_BACKEND', MYSQLPOOL_BACKEND)
backend = getattr(pool, backend)
kwargs = getattr(settings, 'MYSQLPOOL_ARGUMENTS', {})
kwargs.setdefault('poolclass', backend)
# The user can override this, but set it by default for safety.
kwargs.setdefault('recycle', MYSQLPOOL_TIMEOUT)
MYSQLPOOL = pool.manage(OldDatabase, **kwargs)
return MYSQLPOOL
示例12: _connect
def _connect(self):
if cfg['CFG_MISCUTIL_SQL_USE_SQLALCHEMY']:
try:
import sqlalchemy.pool as pool
import MySQLdb as mysqldb
mysqldb = pool.manage(mysqldb, use_threadlocal=True)
connect = mysqldb.connect
except ImportError:
cfg['CFG_MISCUTIL_SQL_USE_SQLALCHEMY'] = False
from MySQLdb import connect
else:
from MySQLdb import connect
return connect
示例13: _get_pool
def _get_pool():
"""
Private function to get the database pool instance, or create one if it's not available yet.
:returns: The connection pool instance
"""
global _pool
if _pool is None:
# FIXME: Use pool size and other parameters from config
_pool = dbpool.manage(MySQLdb, pool_size=1, use_threadlocal=True)
return _pool
示例14: test_manager_with_key
def test_manager_with_key(self):
class NoKws(object):
def connect(self, arg):
return MockConnection()
manager = pool.manage(NoKws(), use_threadlocal=True)
c1 = manager.connect('foo.db', sa_pool_key="a")
c2 = manager.connect('foo.db', sa_pool_key="b")
c3 = manager.connect('bar.db', sa_pool_key="a")
assert c1.cursor() is not None
assert c1 is not c2
assert c1 is c3
示例15: get_pool
def get_pool():
"""Create one and only one pool using the configured settings."""
global MYSQLPOOL
if MYSQLPOOL is None:
backend_name = getattr(settings, "SHIELD_MYSQL_POOL_BACKEND", DEFAULT_BACKEND)
backend = getattr(local_pool, backend_name)
kwargs = getattr(settings, "SHIELD_MYSQL_POOL_ARGUMENTS", {})
kwargs.setdefault("poolclass", backend)
kwargs.setdefault("recycle", DEFAULT_POOL_TIMEOUT)
MYSQLPOOL = sa_pool.manage(OldDatabase, **kwargs)
setattr(MYSQLPOOL, "_pid", os.getpid())
if getattr(MYSQLPOOL, "_pid", None) != os.getpid():
sa_pool.clear_managers()
return MYSQLPOOL