Files
Home-AssistantConfig/deps/sqlalchemy/__pycache__/pool.cpython-34.pyc

564 lines
44 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
|<7C><>Wt<57><00>@s<>dZddlZddlZddlZddlmZmZmZmZm Z ddl m
Z ddl m Z m Z mZddlmZiZdd <00>Zd
d <00>Ze jd <00>Ze jd <00>Ze jd<00>ZGdd<00>de<00>ZGdd<00>dej<00>ZGdd<00>de<00>Zddd<00>Ze<00>ZGdd<00>de<00>Z Gdd<00>de<00>Z!Gdd<00>de<00>Z"Gdd<00>de<00>Z#Gdd <00>d e<00>Z$Gd!d"<00>d"e<00>Z%Gd#d$<00>d$e<00>Z&dS)%a{Connection pooling for DB-API connections.
Provides a number of connection pool implementations for a variety of
usage scenarios and thread behavior requirements imposed by the
application, DB-API or database itself.
Also provides a DB-API 2.0 connection proxying mechanism allowing
regular DB-API connect() methods to be transparently managed by a
SQLAlchemy connection pool.
<EFBFBD>N<>)<05>exc<78>log<6F>event<6E>
interfaces<EFBFBD>util)<01>queue)<03> threading<6E>memoized_property<74>chop_traceback)<01>dequec Ks>y t|SWn+tk
r9tj|t||<00><00>SYnXdS)aIReturn a proxy for a DB-API module that automatically
pools connections.
Given a DB-API 2.0 module and pool management parameters, returns
a proxy for the module that will automatically pool connections,
creating new connection pools for each distinct set of connection
arguments sent to the decorated module's connect() function.
:param module: a DB-API 2.0 database module
:param poolclass: the class used by the pool module to provide
pooling. Defaults to :class:`.QueuePool`.
:param \*\*params: will be passed through to *poolclass*
N)<04>proxies<65>KeyError<6F>
setdefault<EFBFBD>_DBProxy)<02>module<6C>params<6D>r<00>5/tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/pool.py<70>manage!s  rcCs/xtj<00>D]}|j<00>q Wtj<00>dS)zYRemove all current DB-API 2.0 managers.
All pools and connections are disposed.
N)r <00>values<65>close<73>clear)<01>managerrrr<00>clear_managers8sr<00>reset_rollback<63> reset_commit<69>
reset_nonec@s:eZdZdZdd<00>Zdd<00>Zdd<00>ZdS) <09> _ConnDialectz<74>partial implementation of :class:`.Dialect`
which provides DBAPI connection methods.
When a :class:`.Pool` is combined with an :class:`.Engine`,
the :class:`.Engine` replaces this with its own
:class:`.Dialect`.
cCs|j<00>dS)N)<01>rollback)<02>self<6C>dbapi_connectionrrr<00> do_rollbackRsz_ConnDialect.do_rollbackcCs|j<00>dS)N)<01>commit)r r!rrr<00> do_commitUsz_ConnDialect.do_commitcCs|j<00>dS)N)r)r r!rrr<00>do_closeXsz_ConnDialect.do_closeN)<07>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r"r$r%rrrrrGs   rc @seZdZdZe<00>Zd'dddddddddd<00> Zedd <00><00>Zej d
d <00><00>Zd d <00>Z
d d<00>Z e j dd<00>dd<00><00>Zdd<00>Zdd<00>Zddd<00>Zdd<00>Zdd<00>Zdd<00>Zdd <00>Zd!d"<00>Zd#d$<00>Zd%d&<00>ZdS)(<28>Poolz)Abstract base class for connection pools.rNFTc Cs<>|r||_|_n d|_tj|d|<00>tj<00>|_||_||_d|_ ||_
|ddt fkr<>t |_ nU|dddt fkr<>t |_ n1|dtfkr<>t|_ ntjd |<16><00>||_| r|jj| d
d<00>n|
r|
|_n|rKx*|D]\} } tj|| | <00>q%Wn|rtjd <00>x|D]} |j| <00>qeWndS) a<>
Construct a Pool.
:param creator: a callable function that returns a DB-API
connection object. The function will be called with
parameters.
:param recycle: If set to non -1, number of seconds between
connection recycling, which means upon checkout, if this
timeout is surpassed the connection will be closed and
replaced with a newly opened connection. Defaults to -1.
:param logging_name: String identifier which will be used within
the "name" field of logging records generated within the
"sqlalchemy.pool" logger. Defaults to a hexstring of the object's
id.
:param echo: If True, connections being pulled and retrieved
from the pool will be logged to the standard output, as well
as pool sizing information. Echoing can also be achieved by
enabling logging for the "sqlalchemy.pool"
namespace. Defaults to False.
:param use_threadlocal: If set to True, repeated calls to
:meth:`connect` within the same application thread will be
guaranteed to return the same connection object, if one has
already been retrieved from the pool and has not been
returned yet. Offers a slight performance advantage at the
cost of individual transactions by default. The
:meth:`.Pool.unique_connection` method is provided to return
a consistenty unique connection to bypass this behavior
when the flag is set.
.. warning:: The :paramref:`.Pool.use_threadlocal` flag
**does not affect the behavior** of :meth:`.Engine.connect`.
:meth:`.Engine.connect` makes use of the
:meth:`.Pool.unique_connection` method which **does not use thread
local context**. To produce a :class:`.Connection` which refers
to the :meth:`.Pool.connect` method, use
:meth:`.Engine.contextual_connect`.
Note that other SQLAlchemy connectivity systems such as
:meth:`.Engine.execute` as well as the orm
:class:`.Session` make use of
:meth:`.Engine.contextual_connect` internally, so these functions
are compatible with the :paramref:`.Pool.use_threadlocal` setting.
.. seealso::
:ref:`threadlocal_strategy` - contains detail on the
"threadlocal" engine strategy, which provides a more comprehensive
approach to "threadlocal" connectivity for the specific
use case of using :class:`.Engine` and :class:`.Connection` objects
directly.
:param reset_on_return: Determine steps to take on
connections as they are returned to the pool.
reset_on_return can have any of these values:
* ``"rollback"`` - call rollback() on the connection,
to release locks and transaction resources.
This is the default value. The vast majority
of use cases should leave this value set.
* ``True`` - same as 'rollback', this is here for
backwards compatibility.
* ``"commit"`` - call commit() on the connection,
to release locks and transaction resources.
A commit here may be desirable for databases that
cache query plans if a commit is emitted,
such as Microsoft SQL Server. However, this
value is more dangerous than 'rollback' because
any data changes present on the transaction
are committed unconditionally.
* ``None`` - don't do anything on the connection.
This setting should only be made on a database
that has no transaction support at all,
namely MySQL MyISAM. By not doing anything,
performance can be improved. This
setting should **never be selected** for a
database that supports transactions,
as it will lead to deadlocks and stale
state.
* ``"none"`` - same as ``None``
.. versionadded:: 0.9.10
* ``False`` - same as None, this is here for
backwards compatibility.
.. versionchanged:: 0.7.6
:paramref:`.Pool.reset_on_return` accepts ``"rollback"``
and ``"commit"`` arguments.
:param events: a list of 2-tuples, each of the form
``(callable, target)`` which will be passed to :func:`.event.listen`
upon construction. Provided here so that event listeners
can be assigned via :func:`.create_engine` before dialect-level
listeners are applied.
:param listeners: Deprecated. A list of
:class:`~sqlalchemy.interfaces.PoolListener`-like objects or
dictionaries of callables that receive events when DB-API
connections are created, checked out and checked in to the
pool. This has been superseded by
:func:`~sqlalchemy.event.listen`.
NZechoflagrrT<>noneFr#z'Invalid value for 'reset_on_return': %rZonly_propagatezZThe 'listeners' argument to Pool (and create_engine()) is deprecated. Use event.listen().)<1A> logging_name<6D>_orig_logging_namerZinstance_loggerr <00>local<61> _threadconns<6E>_creator<6F>_recycle<6C>_invalidate_time<6D>_use_threadlocalr<00>_reset_on_returnrrr<00> ArgumentError<6F>echo<68>dispatch<63>_update<74>_dialectr<00>listenrZwarn_deprecated<65> add_listener)r <00>creator<6F>recycler6<00>use_threadlocalr,<00>reset_on_returnZ listeners<72>events<74> _dispatchr9<00>fn<66>target<65>lrrr<00>__init__bs>t        
   z Pool.__init__cCs |jdS)Nr0)<01>__dict__)r rrrr0<00>sz Pool._creatorcCs#||jd<|j|<00>|_dS)Nr0)rF<00>_should_wrap_creator<6F>_invoke_creator)r r<rrrr0s c s<>ytj|jdd<00>}Wn"tk
r@<01>fdd<00>SYnX|ddk rat|d<19>pdd}t|d<19>|}|d|dfdgd fkr<><00>S|d kr<><00>S<>fd
d<00>SdS) zlDetect if creator accepts a single argument, or is sent
as a legacy style no-arg function.
Zno_selfTcs<00><00>S)Nr)<01>crec)r<rr<00><lambda>sz+Pool._should_wrap_creator.<locals>.<lambda><3E>Nr<00>connection_recordrcs<00><00>S)Nr)rI)r<rrrJs)N)rZget_callable_argspecr0<00> TypeError<6F>len)r r<ZargspecZ defaultedZ positionalsr)r<rrGs &# zPool._should_wrap_creatorc CsY|jjd|<00>y|jj|<00>Wn+tk
rT|jjd|dd<00>YnXdS)NzClosing connection %rzException closing connection %r<>exc_infoT)<06>logger<65>debugr9r%<00> Exception<6F>error)r <00>
connectionrrr<00>_close_connections   zPool._close_connectiong<6E><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD>@z4Pool.add_listener is deprecated. Use event.listen()cCstjj||<00>dS)aAdd a :class:`.PoolListener`-like object to this pool.
``listener`` may be an object that implements some or all of
PoolListener, or a dictionary of callables containing implementations
of some or all of the named methods in PoolListener.
N)rZ PoolListenerZ_adapt_listener)r Zlistenerrrrr;'s
zPool.add_listenercCs tj|<00>S)a<>Produce a DBAPI connection that is not referenced by any
thread-local context.
This method is equivalent to :meth:`.Pool.connect` when the
:paramref:`.Pool.use_threadlocal` flag is not set to True.
When :paramref:`.Pool.use_threadlocal` is True, the
:meth:`.Pool.unique_connection` method provides a means of bypassing
the threadlocal context.
)<02>_ConnectionFairy<72> _checkout)r rrr<00>unique_connection3s zPool.unique_connectioncCs
t|<00>S)z6Called by subclasses to create a new ConnectionRecord.)<01>_ConnectionRecord)r rrr<00>_create_connection@szPool._create_connectioncCsct|dd<00>}| s+|j|jkr=tj<00>|_nt|dd<00>r_|j|<00>ndS)a<>Mark all connections established within the generation
of the given connection as invalidated.
If this pool's last invalidate time is before when the given
connection was created, update the timestamp til now. Otherwise,
no action is performed.
Connections with a start time prior to this pool's invalidation
time will be recycled upon next checkout.
<20>_connection_recordN<64>is_validF)<05>getattrr2<00> starttime<6D>time<6D>
invalidate)r rT<00> exception<6F>recrrr<00> _invalidateEs
zPool._invalidatecCs t<00><00>dS)aReturn a new :class:`.Pool`, of the same class as this one
and configured with identical creation arguments.
This method is used in conjunction with :meth:`dispose`
to close out an entire :class:`.Pool` and create a new one in
its place.
N)<01>NotImplementedError)r rrr<00>recreateVs
z Pool.recreatecCs t<00><00>dS)z<>Dispose of this pool.
This method leaves the possibility of checked-out connections
remaining open, as it only affects connections that are
idle in the pool.
See also the :meth:`Pool.recreate` method.
N)rd)r rrr<00>disposebs z Pool.disposec Csg|jstj|<00>Sy|jj<00>}Wntk
r=YnX|dk rT|j<00>Stj||j<00>S)z<>Return a DBAPI connection from the pool.
The connection is instrumented such that when its
``close()`` method is called, the connection will be returned to
the pool.
N)r3rVrWr/<00>current<6E>AttributeError<6F>_checkout_existing)r rbrrr<00>connectos    
z Pool.connectc Cs?|jr.y |j`Wq.tk
r*Yq.Xn|j|<00>dS)z<>Given a _ConnectionRecord, return it to the :class:`.Pool`.
This method is called when an instrumented DBAPI connection
has its ``close()`` method called.
N)r3r/rgrh<00>_do_return_conn)r <00>recordrrr<00> _return_conn<6E>s    zPool._return_conncCs t<00><00>dS)z7Implementation for :meth:`get`, supplied by subclasses.N)rd)r rrr<00>_do_get<65>sz Pool._do_getcCs t<00><00>dS)z?Implementation for :meth:`return_conn`, supplied by subclasses.N)rd)r <00>connrrrrk<00>szPool._do_return_conncCs t<00><00>dS)N)rd)r rrr<00>status<75>sz Pool.status<75><73><EFBFBD><EFBFBD><EFBFBD>)r&r'r(r)rr9rE<00>propertyr0<00>setterrGrUrZ
deprecatedr;rXrZrcrerfrjrmrnrkrprrrrr*\s4  <0F>       r*c@s<>eZdZdZdd<00>ZdZdZejdd<00><00>Z e
dd <00><00>Z d
d <00>Z d d <00>Z dddd<00>Zdd<00>Zdd<00>Zdd<00>ZdS)rYa<>Internal object which maintains an individual DBAPI connection
referenced by a :class:`.Pool`.
The :class:`._ConnectionRecord` object always exists for any particular
DBAPI connection whether or not that DBAPI connection has been
"checked out". This is in contrast to the :class:`._ConnectionFairy`
which is only a public facade to the DBAPI connection while it is checked
out.
A :class:`._ConnectionRecord` may exist for a span longer than that
of a single DBAPI connection. For example, if the
:meth:`._ConnectionRecord.invalidate`
method is called, the DBAPI connection associated with this
:class:`._ConnectionRecord`
will be discarded, but the :class:`._ConnectionRecord` may be used again,
in which case a new DBAPI connection is produced when the :class:`.Pool`
next uses this record.
The :class:`._ConnectionRecord` is delivered along with connection
pool events, including :meth:`.PoolEvents.connect` and
:meth:`.PoolEvents.checkout`, however :class:`._ConnectionRecord` still
remains an internal object whose API and internals may change.
.. seealso::
:class:`._ConnectionFairy`
cCsc||_|j<00>|_t<00>|_|jjj|j<00>j|j|<00>|jj |j|<00>dS)N)
<EFBFBD>_ConnectionRecord__pool<6F>_ConnectionRecord__connectrTr <00>finalize_callbackr7Z first_connectZ
for_modifyZ exec_oncerj)r <00>poolrrrrE<00>s
  %z_ConnectionRecord.__init__NrcCsiS)z<>The ``.info`` dictionary associated with the DBAPI connection.
This dictionary is shared among the :attr:`._ConnectionFairy.info`
and :attr:`.Connection.info` accessors.
r)r rrr<00>info<66>sz_ConnectionRecord.infocs<><00>j<00><00>y<00>j<00><00>Wn%tj<00><00><01>j<00>WdQXYnX<>j<00><00>t<00><00><00><00>}tj|<00><00><00><00>fdd<00><00><00>_ t
j <00><00><01>r<><00>j j d<00><00>n|S)Ncstot<00><00><00>|<00><00>S)N)<01>_finalize_fairy)<01>ref)r!r6rwrbrrrJ<00>sz,_ConnectionRecord.checkout.<locals>.<lambda>z#Connection %r checked out from pool)rn<00>get_connectionr<00> safe_reraise<73>checkinZ_should_log_debugrV<00>weakrefrz<00> fairy_ref<65>_refs<66>addrPrQ)<03>clsrw<00>fairyr)r!r6rwrbr<00>checkout<75>s    !  
z_ConnectionRecord.checkoutcCswd|_|j}|j}x&|jrC|jj<00>}||<00>qW|jjrf|jj||<00>n|j|<00>dS)N)rrTrtrv<00>popr7r}rm)r rTrwZ finalizerrrrr}<00>s     z_ConnectionRecord.checkincCs |jdk r|j<00>ndS)N)rT<00>_ConnectionRecord__close)r rrrrsz_ConnectionRecord.closeFcCs<>|jdkrdS|r8|jjj|j||<00>n|jjj|j||<00>|dk r<>|jjjd|r{dnd|j|jj|<00>n(|jjjd|r<>dnd|j<00>|r<>t j <00>|_
n|j <00>d|_dS)a<>Invalidate the DBAPI connection held by this :class:`._ConnectionRecord`.
This method is called for all connection invalidations, including
when the :meth:`._ConnectionFairy.invalidate` or
:meth:`.Connection.invalidate` methods are called, as well as when any
so-called "automatic invalidation" condition occurs.
:param e: an exception object indicating a reason for the invalidation.
:param soft: if True, the connection isn't closed; instead, this
connection will be recycled on next checkout.
.. versionadded:: 1.0.3
.. seealso::
:ref:`pool_connection_invalidation`
Nz*%sInvalidate connection %r (reason: %s:%s)zSoft <20>z%sInvalidate connection %r) rTrtr7Zsoft_invalidater`rPrx<00> __class__r&r_<00>_soft_invalidate_timer<65>)r <00>e<>softrrrr`s$   

z_ConnectionRecord.invalidatecCs<>d}|jdkr_|jj<00>|j<00>|_|jjjr%|jjj|j|<00>q%n<>|jjdkr<>tj<00>|j |jjkr<>|jj
jd|j<00>d}ns|jj |j kr<>|jj
jdd|j<00>d}n8|j |j kr%|jj
jdd|j<00>d}n|r<>|j <00>|jj<00>d|_|j<00>|_|jjjr<>|jjj|j|<00>q<>n|jS) NFrz)Connection %r exceeded timeout; recyclingTz4Connection %r invalidated due to pool invalidation; Z recyclingz:Connection %r invalidated due to local soft invalidation; rq)rTrxrrurtr7rjr1r_r^rPr2r<>r<>)r r=rrrr{/s@  
  
  
 
  z _ConnectionRecord.get_connectioncCs$|jj<00>|jj|j<00>dS)N)rvrrtrUrT)r rrr<00>__closeXs z_ConnectionRecord.__closecCs<>y?tj<00>|_|jj|<00>}|jjjd|<00>|SWn>tk
r}z|jjjd|<00><01>WYdd}~XnXdS)NzCreated new connection %rzError on connect(): %s)r_r^rtrHrPrQrR)r rTr<>rrrZ __connect\sz_ConnectionRecord.__connect)r&r'r(r)rErTr<>rr
rx<00> classmethodr<64>r}rr`r{r<>rurrrrrY<00>s 
 
 + ) rYcCs4tj|<00>|dk r,|j|k r,dS|dk r|rZ|rZ|jjd|<00>nyT|prt|||<00>}|j|ks<>t<00>|j|<00>|s<>|j |<00>nWqt
k
r}zI|jj ddd<00>|r<>|j d|<00>nt |t<00>s<01>nWYdd}~XqXn|r0|j<00>ndS)zfCleanup for a :class:`._ConnectionFairy` whether or not it's already
been garbage collected.
Nz$Connection %r being returned to poolz!Exception during reset or similarrOTr<54>)r<><00>discardrrPrQrVrT<00>AssertionError<6F>_resetrU<00> BaseExceptionrSr`<00>
isinstancerRr})rTrLrwrzr6r<>r<>rrrrygs0     
    ryc@s<>eZdZdZdd<00>ZdZdZdZedddd<00><00>Z dd<00>Z
d d
<00>Z e Z d d <00>Z ed d<00><00>Zedd<00><00>Zejdd<00><00>Zdddd<00>Zdd<00>Zdd<00>Zdd<00>Zdd<00>ZdS)rVaXProxies a DBAPI connection and provides return-on-dereference
support.
This is an internal object used by the :class:`.Pool` implementation
to provide context management to a DBAPI connection delivered by
that :class:`.Pool`.
The name "fairy" is inspired by the fact that the
:class:`._ConnectionFairy` object's lifespan is transitory, as it lasts
only for the length of a specific DBAPI connection being checked out from
the pool, and additionally that as a transparent proxy, it is mostly
invisible.
.. seealso::
:class:`._ConnectionRecord`
cCs||_||_||_dS)N)rTr[<00>_echo)r r!rLr6rrrrE<00>s  z_ConnectionFairy.__init__NcCs<>|sKtj|<00>}||_d|_|dk rKtj|<00>|_qKn|jdkrltj d<00><00>n|jd7_|j
j s<>|jdkr<>|Sd}x<>|dkrpy$|j
j|j|j |<00>|SWq<57>tj k
rl}zs|j jd|<00>|j j|<00>y|j j<00>|_Wn(tj<00><00>|j j<00>WdQXYnX|d8}WYdd}~Xq<58>Xq<58>W|j jd<00>|j<00>tj d<00><00>dS)NrzThis connection is closedr<00>z&Disconnection detected on checkout: %sz+Reconnection attempts exhausted on checkout)rYr<><00>_pool<6F>_counterr~rzrgrTrZInvalidRequestErrorr7r[ZDisconnectionErrorrPrxr`r{rr|r})r<>rwZ threadconnsr<73><00>attemptsr<73>rrrrW<00>s>    
 !
z_ConnectionFairy._checkoutcCstj|jd|<00>S)Nr<4E>)rVrWr<>)r rrrri<00>sz#_ConnectionFairy._checkout_existingcCs>t|j|j|jd|jd|<00>d|_d|_dS)Nr<4E>)ryrTr[r<>r<>)r rrr<00>_checkin<69>s z_ConnectionFairy._checkincCs|jjr%|jj||j<00>n|jtkr<>|jrh|jjd|j|j r^dnd<00>n|j r<>|j j
<00>q|j j |<00>no|jt kr|jr<>|jjd|j|j r<>dnd<00>n|j r<>|j j<00>q|j j|<00>ndS)Nz"Connection %s rollback-on-return%sz , via agentr<74>z Connection %s commit-on-return%s)r7<00>resetr[r4rr<>rPrQrT<00> _reset_agentrr9r"rr#r$)r rwrrrr<><00>s$       z_ConnectionFairy._resetcCs
|jjS)N)r<>rP)r rrr<00>_loggersz_ConnectionFairy._loggercCs |jdk S)zbReturn True if this :class:`._ConnectionFairy` still refers
to an active DBAPI connection.N)rT)r rrrr\sz_ConnectionFairy.is_validcCs
|jjS)aInfo dictionary associated with the underlying DBAPI connection
referred to by this :class:`.ConnectionFairy`, allowing user-defined
data to be associated with the connection.
The data here will follow along with the DBAPI connection including
after it is returned to the connection pool and used again
in subsequent instances of :class:`._ConnectionFairy`. It is shared
with the :attr:`._ConnectionRecord.info` and :attr:`.Connection.info`
accessors.
)r[rx)r rrrrxs z_ConnectionFairy.infoFcCse|jdkr tjd<00>dS|jrE|jjd|d|<00>n|sad|_|j<00>ndS)a<>Mark this connection as invalidated.
This method can be called directly, and is also called as a result
of the :meth:`.Connection.invalidate` method. When invoked,
the DBAPI connection is immediately closed and discarded from
further use by the pool. The invalidation mechanism proceeds
via the :meth:`._ConnectionRecord.invalidate` internal method.
:param e: an exception object indicating a reason for the invalidation.
:param soft: if True, the connection isn't closed; instead, this
connection will be recycled on next checkout.
.. versionadded:: 1.0.3
.. seealso::
:ref:`pool_connection_invalidation`
Nz.Can't invalidate an already-closed connection.r<>r<>)rTr<00>warnr[r`r<>)r r<>r<>rrrr`.s   z_ConnectionFairy.invalidatecOs|jj||<00>S)z<>Return a new DBAPI cursor for the underlying connection.
This method is a proxy for the ``connection.cursor()`` DBAPI
method.
)rT<00>cursor)r <00>args<67>kwargsrrrr<>Msz_ConnectionFairy.cursorcCst|j|<00>S)N)r]rT)r <00>keyrrr<00> __getattr__Vsz_ConnectionFairy.__getattr__cCsl|jdk rhtj|j<00>d|j_d|j_|jj|j<00>|jj<00>|_d|_ndS)a"Separate this connection from its Pool.
This means that the connection will no longer be returned to the
pool when closed, and will instead be literally closed. The
containing ConnectionRecord is separated from the DB-API connection,
and will create a new connection when next used.
Note that any overall connection limiting constraints imposed by a
Pool implementation may be violated after a detach, as the detached
connection is removed from the pool's knowledge and control.
N) r[r<><00>removerrTr<>rkrx<00>copy)r rrr<00>detachYs   z_ConnectionFairy.detachcCs/|jd8_|jdkr+|j<00>ndS)Nrr)r<>r<>)r rrrrosz_ConnectionFairy.close)r&r'r(r)rErTr[r<>r<>rWrir<>Z_closer<65>rrr<>r\rr
rxr`r<>r<>r<>rrrrrrV<00>s&  *     rVc@smeZdZdZddd<00>Zdd<00>Zdd<00>Zd d
<00>Zd d <00>Zd d<00>Z dd<00>Z
dS)<12>SingletonThreadPoola<6C>A Pool that maintains one connection per thread.
Maintains one connection per each thread, never moving a connection to a
thread other than the one which it was created in.
.. warning:: the :class:`.SingletonThreadPool` will call ``.close()``
on arbitrary connections that exist beyond the size setting of
``pool_size``, e.g. if more unique **thread identities**
than what ``pool_size`` states are used. This cleanup is
non-deterministic and not sensitive to whether or not the connections
linked to those thread identities are currently in use.
:class:`.SingletonThreadPool` may be improved in a future release,
however in its current status it is generally used only for test
scenarios using a SQLite ``:memory:`` database and is not recommended
for production use.
Options are the same as those of :class:`.Pool`, as well as:
:param pool_size: The number of threads in which to maintain connections
at once. Defaults to five.
:class:`.SingletonThreadPool` is used by the SQLite dialect
automatically when a memory-based database is used.
See :ref:`sqlite_toplevel`.
<20>cKsEd|d<tj|||<00>tj<00>|_t<00>|_||_dS)NTr>)r*rEr r.<00>_conn<6E>set<65>
_all_conns<EFBFBD>size)r r<<00> pool_size<7A>kwrrrrE<00>s

 zSingletonThreadPool.__init__cCsh|jjd<00>|j|jd|jd|jd|jd|jd|jd|j d|j
d |j <00>S)
NzPool recreatingr<67>r=r6r,r>r?rAr9) rPrxr<>r0r<>r1r6r-r3r4r7r9)r rrrre<00>s       zSingletonThreadPool.recreatec CsHx4|jD])}y|j<00>Wq
tk
r2Yq
Xq
W|jj<00>dS)zDispose of this pool.N)r<>rrRr)r rorrrrf<00>s   zSingletonThreadPool.disposecCs<x5t|j<00>|jkr7|jj<00>}|j<00>qWdS)N)rNr<>r<>r<>r)r <00>crrr<00>_cleanup<75>szSingletonThreadPool._cleanupcCsdt|<00>t|j<00>fS)Nz"SingletonThreadPool id:%d size: %d)<03>idrNr<>)r rrrrp<00>szSingletonThreadPool.statuscCsdS)Nr)r rorrrrk<00>sz#SingletonThreadPool._do_return_connc Cs<>y|jj<00>}|r|SWntk
r1YnX|j<00>}tj|<00>|j_t|j<00>|jkrx|j <00>n|jj
|<00>|S)N) r<>rgrhrZr~rzrNr<>r<>r<>r<>)r r<>rrrrn<00>s   zSingletonThreadPool._do_getN) r&r'r(r)rErerfr<>rprkrnrrrrr<>us    r<>c@s<>eZdZdZddddd<00>Zdd<00>Zd d
<00>Zd d <00>Zd d<00>Zdd<00>Z dd<00>Z
dd<00>Z dd<00>Z dd<00>Z dd<00>Zdd<00>ZdS)<1E> QueuePoolz<6C>A :class:`.Pool` that imposes a limit on the number of open connections.
:class:`.QueuePool` is the default pooling implementation used for
all :class:`.Engine` objects, unless the SQLite dialect is in use.
r<><00>
<00>cKsWtj|||<00>tj|<00>|_d||_||_||_tj <00>|_
dS)a<>
Construct a QueuePool.
:param creator: a callable function that returns a DB-API
connection object, same as that of :paramref:`.Pool.creator`.
:param pool_size: The size of the pool to be maintained,
defaults to 5. This is the largest number of connections that
will be kept persistently in the pool. Note that the pool
begins with no connections; once this number of connections
is requested, that number of connections will remain.
``pool_size`` can be set to 0 to indicate no size limit; to
disable pooling, use a :class:`~sqlalchemy.pool.NullPool`
instead.
:param max_overflow: The maximum overflow size of the
pool. When the number of checked-out connections reaches the
size set in pool_size, additional connections will be
returned up to this limit. When those additional connections
are returned to the pool, they are disconnected and
discarded. It follows then that the total number of
simultaneous connections the pool will allow is pool_size +
`max_overflow`, and the total number of "sleeping"
connections the pool will allow is pool_size. `max_overflow`
can be set to -1 to indicate no overflow limit; no limit
will be placed on the total number of concurrent
connections. Defaults to 10.
:param timeout: The number of seconds to wait before giving up
on returning a connection. Defaults to 30.
:param \**kw: Other keyword arguments including
:paramref:`.Pool.recycle`, :paramref:`.Pool.echo`,
:paramref:`.Pool.reset_on_return` and others are passed to the
:class:`.Pool` constructor.
rN) r*rE<00>
sqla_queue<EFBFBD>Queuer<65><00> _overflow<6F> _max_overflow<6F>_timeoutr <00>Lock<63>_overflow_lock)r r<r<><00> max_overflow<6F>timeoutr<74>rrrrE<00>s '   zQueuePool.__init__cCsOy|jj|d<00>Wn1tjk
rJz|j<00>Wd|j<00>XYnXdS)NF)r<><00>putr<74><00>Fullr<00> _dec_overflow)r rorrrrks zQueuePool._do_return_conncCs|jdk}y2|o'|j|jk}|jj||j<00>SWn<57>tjk
r<>|r<>|j|jkr<>|s||j<00>Stj d|j
<00>|j <00>|jf<16><00>n|j <00>r<>y|j <00>SWq<57>tj<00><00>|j<00>WdQXYq<59>Xn
|j<00>SYnXdS)NrzPQueuePool limit of size %d overflow %d reached, connection timed out, timeout %drq)r<>r<>r<><00>getr<74>r<><00>Emptyrnr<00> TimeoutErrorr<72><00>overflow<6F> _inc_overflowrZrr|r<>)r Z use_overflow<6F>waitrrrrns$
%  zQueuePool._do_getc
Cs_|jdkr"|jd7_dS|j<00>.|j|jkrQ|jd7_dSdSWdQXdS)NrTFrq)r<>r<>r<>)r rrrr<>(s
zQueuePool._inc_overflowc
CsI|jdkr"|jd8_dS|j<00>|jd8_dSWdQXdS)NrTrq)r<>r<>r<>)r rrrr<>3s 
zQueuePool._dec_overflowcCs}|jjd<00>|j|jd|jjd|jd|jd|jd|j d|j
d|j d |j d
|j d |j<00>
S) NzPool recreatingr<67>r<>r<>r=r6r,r>r?rAr9)rPrxr<>r0r<><00>maxsizer<65>r<>r1r6r-r3r4r7r9)r rrrre;s      zQueuePool.recreatec Csox<y |jjd<00>}|j<00>Wqtjk
r;PYqXqd|j<00>|_|jjd|j <00><00>dS)NFrzPool disposed. %s)
r<EFBFBD>r<>rr<>r<>r<>r<>rPrxrp)r rorrrrfGs zQueuePool.disposecCs,d|j<00>|j<00>|j<00>|j<00>fS)Nz_Pool size: %d Connections in pool: %d Current Overflow: %d Current Checked out connections: %d)r<><00> checkedinr<6E><00>
checkedout)r rrrrpRs
   zQueuePool.statuscCs
|jjS)N)r<>r<>)r rrrr<>ZszQueuePool.sizecCs |jj<00>S)N)r<><00>qsize)r rrrr<>]szQueuePool.checkedincCs|jS)N)r<>)r rrrr<>`szQueuePool.overflowcCs|jj|jj<00>|jS)N)r<>r<>r<>r<>)r rrrr<>cszQueuePool.checkedoutN)r&r'r(r)rErkrnr<>r<>rerfrpr<>r<>r<>r<>rrrrr<><00>s .      r<>c@sReZdZdZdd<00>Zdd<00>Zdd<00>Zdd <00>Zd
d <00>Zd S) <0A>NullPoola<6C>A Pool which does not pool connections.
Instead it literally opens and closes the underlying DB-API connection
per each connection open/close.
Reconnect-related functions such as ``recycle`` and connection
invalidation are not supported by this Pool implementation, since
no connections are held persistently.
.. versionchanged:: 0.7
:class:`.NullPool` is used by the SQlite dialect automatically
when a file-based database is used. See :ref:`sqlite_toplevel`.
cCsdS)Nr<4E>r)r rrrrpxszNullPool.statuscCs|j<00>dS)N)r)r rorrrrk{szNullPool._do_return_conncCs
|j<00>S)N)rZ)r rrrrn~szNullPool._do_getcCs_|jjd<00>|j|jd|jd|jd|jd|jd|jd|j d|j
<00>S) NzPool recreatingr=r6r,r>r?rAr9) rPrxr<>r0r1r6r-r3r4r7r9)r rrrre<00>s      zNullPool.recreatecCsdS)Nr)r rrrrf<00>szNullPool.disposeN) r&r'r(r)rprkrnrerfrrrrr<>gs     r<>c@s<>eZdZdZedd<00><00>Zedd<00><00>Zdd<00>Zdd <00>Zd
d <00>Z d d <00>Z
dd<00>Z dd<00>Z dS)<13>
StaticPoola.A Pool of exactly one connection, used for all requests.
Reconnect-related functions such as ``recycle`` and connection
invalidation (which is also used to support auto-reconnect) are not
currently supported by this Pool implementation but may be implemented
in a future release.
cCs
|j<00>S)N)r0)r rrrr<><00>szStaticPool._conncCs
t|<00>S)N)rY)r rrrrT<00>szStaticPool.connectioncCsdS)Nr<4E>r)r rrrrp<00>szStaticPool.statuscCs,d|jkr(|jj<00>d|_ndS)Nr<4E>)rFr<>r)r rrrrf<00>s zStaticPool.disposecCsb|jjd<00>|jd|jd|jd|jd|jd|jd|jd|j d |j
<00>S)
NzPool recreatingr<r=r>r?r6r,rAr9) rPrxr<>r0r1r3r4r6r-r7r9)r rrrre<00>s      zStaticPool.recreatecCs|jS)N)r<>)r rrrrZ<00>szStaticPool._create_connectioncCsdS)Nr)r rorrrrk<00>szStaticPool._do_return_conncCs|jS)N)rT)r rrrrn<00>szStaticPool._do_getN) r&r'r(r)r
r<>rTrprfrerZrkrnrrrrr<><00>s     r<>c@s^eZdZdZdd<00>Zdd<00>Zdd<00>Zdd <00>Zd
d <00>Zd d <00>Z dS)<0F> AssertionPoola<6C>A :class:`.Pool` that allows at most one checked out connection at
any given time.
This will raise an exception if more than one connection is checked out
at a time. Useful for debugging code that is using more connections
than desired.
.. versionchanged:: 0.7
:class:`.AssertionPool` also logs a traceback of where
the original connection was checked out, and reports
this in the assertion error raised.
cOsGd|_d|_|jdd<00>|_d|_tj|||<00>dS)NFZstore_tracebackT)r<><00> _checked_outr<74><00>_store_traceback<63>_checkout_tracebackr*rE)r r<>r<>rrrrE<00>s
   zAssertionPool.__init__cCsdS)Nr<4E>r)r rrrrp<00>szAssertionPool.statuscCs:|jstd<00><00>nd|_||jks6t<00>dS)Nzconnection is not checked outF)r<>r<>r<>)r rorrrrk<00>s  zAssertionPool._do_return_conncCs&d|_|jr"|jj<00>ndS)NF)r<>r<>r)r rrrrf<00>s  zAssertionPool.disposec
CsD|jjd<00>|j|jd|jd|jd|jd|j<00>S)NzPool recreatingr6r,rAr9)rPrxr<>r0r6r-r7r9)r rrrre<00>s
  zAssertionPool.recreatecCs<>|jrJ|jr1ddjt|j<00><00>}nd}td|<17><00>n|jse|j<00>|_nd|_|jr<>tj <00>|_n|jS)Nz at:
%sr<73>z!connection is already checked outT)
r<EFBFBD>r<><00>joinr r<>r<>rZr<><00> traceback<63> format_stack)r <00>suffixrrrrn<00>s      zAssertionPool._do_getN)
r&r'r(r)rErprkrfrernrrrrr<><00>s      r<>c@syeZdZdZedd<00>Zdd<00>Zdd<00>Zdd <00>Zd
d <00>Z d d <00>Z
dd<00>Z dd<00>Z dS)ra Layers connection pooling behavior on top of a standard DB-API module.
Proxies a DB-API 2.0 connect() call to a connection pool keyed to the
specific connect parameters. Other functions and attributes are delegated
to the underlying DB-API module.
cKs7||_||_||_i|_tj<00>|_dS)z<>Initializes a new proxy.
module
a DB-API 2.0 module
poolclass
a Pool class, defaulting to QueuePool
Other parameters are sent to the Pool object's constructor.
N)rr<><00> poolclass<73>poolsr r<><00>_create_pool_mutex)r rr<>r<>rrrrEs
   z_DBProxy.__init__cCs(x!t|j<00>D]}|j|=qWdS)N)<02>listr<74>)r r<>rrrrsz_DBProxy.closecCs|j<00>dS)N)r)r rrr<00>__del__sz_DBProxy.__del__cCst|j|<00>S)N)r]r)r r<>rrrr<>"sz_DBProxy.__getattr__cs<><00>j<00><00><00>}y<00>j|SWn<57>tk
r<><01>jj<00>zf|<00>jkr<><00>jdd<00><01>j<00><00><00>fdd<00><00>j<00>}|<00>j|<|S<>j|SWd<00>jj<00>XYnXdS)N<> sa_pool_keycs<00>jj<00><00><00>S)N)rrjr)r<>r<>r rrrJ/sz#_DBProxy.get_pool.<locals>.<lambda>) <09>
_serializer<EFBFBD>rr<><00>acquirer<65>r<>r<><00>release)r r<>r<>r<>rwr)r<>r<>r r<00>get_pool%s  ! z_DBProxy.get_poolcOs|j||<00>j<00>S)a,Activate a connection to the database.
Connect to the database using this DBProxy's module and the given
connect arguments. If the arguments match an existing pool, the
connection will be returned from the pool's current thread-local
connection instance, or if there is no thread-local connection
instance it will be checked out from the set of pooled connections.
If the pool has no available connections and allows new connections
to be created, a new database connection will be made.
)r<>rj)r r<>r<>rrrrj7sz_DBProxy.connectc Os9|j||<00>}y|j|=Wntk
r4YnXdS)z;Dispose the pool referenced by the given connect arguments.N)r<>r<>r)r r<>r<>r<>rrrrfGs
 z_DBProxy.disposecsAd<00>kr<00>dStt|<00><00>fdd<00>t<00><00>D<><17>S)Nr<4E>cs g|]}|<00>|f<00>qSrr)<02>.0<EFBFBD>k)r<>rr<00>
<listcomp>Vs z'_DBProxy._serialize.<locals>.<listcomp>)<03>tupler<65><00>sorted)r r<>r<>r)r<>rr<>Ps
  z_DBProxy._serializeN) r&r'r(r)r<>rErr<>r<>r<>rjrfr<>rrrrr<00>s       r)'r)r_r<>r~r<>rrrrrrr<>r r
r <00> collectionsr r rr<00>symbolrrr<00>objectrZ
Identifiedr*rYryr<>r<>rVr<>r<>r<>r<>r<>rrrrr<00><module>s4   ( 
<19>E<16>% <16>Z<16>*0>