diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-08-20 19:07:07 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-08-20 19:07:07 +0000 |
| commit | 531faf0e187d756bda92a937a77accd86b813339 (patch) | |
| tree | b9536fe6cafbdeda5d454f26fed0f06982c87541 /lib/sqlalchemy/engine | |
| parent | be16b15f2c0dc33f2491fc6ad1de0f11b1f6c7d4 (diff) | |
| download | sqlalchemy-531faf0e187d756bda92a937a77accd86b813339.tar.gz | |
- Engine and TLEngine assume "threadlocal" behavior on Pool; both use connect()
for contextual connection, unique_connection() for non-contextual.
- Pool use_threadlocal defaults to True, can be set to false at create_engine()
level with pool_threadlocal=False
- made all logger statements in pool conditional based on a flag calcualted once.
- chagned WeakValueDictionary() used for "threadlocal" pool to be a regular dict
referencing weakref objects. WVD had a lot of overhead, apparently. *CAUTION* -
im pretty confident about this change, as the threadlocal dict gets explicitly managed
anyway, tests pass with PG etc., but keep a close eye on this one regardless.
Diffstat (limited to 'lib/sqlalchemy/engine')
| -rw-r--r-- | lib/sqlalchemy/engine/base.py | 9 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/strategies.py | 5 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/threadlocal.py | 21 |
3 files changed, 11 insertions, 24 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 298264362..2e75d358c 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -844,7 +844,7 @@ class Connection(Connectable): return self.__engine.dialect.create_execution_context(connection=self, **kwargs) def __execute_raw(self, context): - if logging.is_info_enabled(self.__engine.logger): + if self.__engine._should_log: self.__engine.logger.info(context.statement) self.__engine.logger.info(repr(context.parameters)) if context.parameters is not None and isinstance(context.parameters, list) and len(context.parameters) > 0 and isinstance(context.parameters[0], (list, tuple, dict)): @@ -1023,6 +1023,7 @@ class Engine(Connectable): self._dialect=dialect self.echo = echo self.logger = logging.instance_logger(self) + self._should_log = logging.is_info_enabled(self.logger) name = property(lambda s:sys.modules[s.dialect.__module__].descriptor()['name'], doc="String name of the [sqlalchemy.engine#Dialect] in use by this ``Engine``.") engine = property(lambda s:s) @@ -1136,7 +1137,7 @@ class Engine(Connectable): This Connection is meant to be used by the various "auto-connecting" operations. """ - return Connection(self, close_with_result=close_with_result, **kwargs) + return Connection(self, self.pool.connect(), close_with_result=close_with_result, **kwargs) def table_names(self, schema=None, connection=None): """Return a list of all table names available in the database. @@ -1183,7 +1184,7 @@ class Engine(Connectable): def raw_connection(self): """Return a DB-API connection.""" - return self.pool.connect() + return self.pool.unique_connection() def log(self, msg): """Log a message using this SQLEngine's logger stream.""" @@ -1223,7 +1224,7 @@ class ResultProxy(object): self.dialect = context.dialect self.closed = False self.cursor = context.cursor - self.__echo = logging.is_debug_enabled(context.engine.logger) + self.__echo = context.engine._should_log self._process_row = self._row_processor() if context.is_select(): self._init_metadata() diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py index a0a6445fd..259ba55c5 100644 --- a/lib/sqlalchemy/engine/strategies.py +++ b/lib/sqlalchemy/engine/strategies.py @@ -85,12 +85,13 @@ class DefaultEngineStrategy(EngineStrategy): # the arguments translate = {'echo': 'echo_pool', 'timeout': 'pool_timeout', - 'recycle': 'pool_recycle'} + 'recycle': 'pool_recycle', + 'use_threadlocal':'pool_threadlocal'} for k in util.get_cls_kwargs(poolclass): tk = translate.get(k, k) if tk in kwargs: pool_args[k] = kwargs.pop(tk) - pool_args['use_threadlocal'] = self.pool_threadlocal() + pool_args.setdefault('use_threadlocal', self.pool_threadlocal()) pool = poolclass(creator, **pool_args) else: if isinstance(pool, poollib._DBProxy): diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py index e9843ea2e..dc6b6007f 100644 --- a/lib/sqlalchemy/engine/threadlocal.py +++ b/lib/sqlalchemy/engine/threadlocal.py @@ -16,7 +16,7 @@ class TLSession(object): try: return self.__transaction._increment_connect() except AttributeError: - return TLConnection(self, close_with_result=close_with_result) + return TLConnection(self, self.engine.pool.connect(), close_with_result=close_with_result) def reset(self): try: @@ -82,9 +82,8 @@ class TLSession(object): class TLConnection(base.Connection): - def __init__(self, session, close_with_result): - base.Connection.__init__(self, session.engine, - close_with_result=close_with_result) + def __init__(self, session, connection, close_with_result): + base.Connection.__init__(self, session.engine, connection, close_with_result=close_with_result) self.__session = session self.__opencount = 1 @@ -160,20 +159,6 @@ class TLEngine(base.Engine): super(TLEngine, self).__init__(*args, **kwargs) self.context = util.ThreadLocal() - def raw_connection(self): - """Return a DB-API connection.""" - - return self.pool.connect() - - def connect(self, **kwargs): - """Return a Connection that is not thread-locally scoped. - - This is the equivalent to calling ``connect()`` on a - base.Engine. - """ - - return base.Connection(self, self.pool.unique_connection()) - def _session(self): if not hasattr(self.context, 'session'): self.context.session = TLSession(self) |
