44
44
<script type="text/javascript" src="../_static/doctools.js"></script>
45
45
<!-- end iterate through sphinx environment script_files -->
47
<script type="text/javascript" src="../_static/detectmobile.js"></script>
47
48
<script type="text/javascript" src="../_static/init.js"></script>
48
49
<link rel="index" title="Index" href="../genindex.html" />
49
50
<link rel="search" title="Search" href="../search.html" />
72
74
<div id="docs-container">
80
<div id="docs-top-navigation-container" class="body-background">
77
81
<div id="docs-header">
82
<div id="docs-version-header">
83
Release: <span class="version-num">0.9.6</span> | Release Date: June 23, 2014
78
86
<h1>SQLAlchemy 0.9 Documentation</h1>
80
<div id="docs-search">
82
<form class="search" action="../search.html" method="get">
83
<input type="text" name="q" size="18" /> <input type="submit" value="Search" />
84
<input type="hidden" name="check_keywords" value="yes" />
85
<input type="hidden" name="area" value="default" />
89
<div id="docs-version-header">
90
Release: <span class="version-num">0.9.4</span> | Release Date: March 28, 2014
97
<div id="docs-top-navigation">
98
<div id="docs-top-page-control" class="docs-navigation-links">
91
<div id="docs-body-container">
93
<div id="fixed-sidebar" class="withsidebar">
96
<div id="docs-sidebar-popout">
97
<h3><a href="../index.html">SQLAlchemy 0.9 Documentation</a></h3>
99
<p id="sidebar-paginate">
100
<a href="index.html" title="SQLAlchemy Core">Up</a> |
102
<a href="connections.html" title="Working with Engines and Connections">Prev</a> |
103
<a href="event.html" title="Events">Next</a>
106
<p id="sidebar-topnav">
107
<a href="../index.html">Contents</a> |
108
<a href="../genindex.html">Index</a>
111
<div id="sidebar-search">
112
<form class="search" action="../search.html" method="get">
113
<input type="text" name="q" size="12" /> <input type="submit" value="Search" />
114
<input type="hidden" name="check_keywords" value="yes" />
115
<input type="hidden" name="area" value="default" />
121
<div id="docs-sidebar">
101
<a href="connections.html" title="previous chapter">Working with Engines and Connections</a>
104
<a href="event.html" title="next chapter">Events</a>
108
<a href="../contents.html">Table of Contents</a> |
109
<a href="../genindex.html">Index</a>
110
| <a href="../_sources/core/pooling.txt">view source
115
<div id="docs-navigation-banner">
116
<a href="../index.html">SQLAlchemy 0.9 Documentation</a>
117
» <a href="index.html" title="SQLAlchemy Core">SQLAlchemy Core</a>
131
<div id="docs-body-container">
133
<div id="docs-sidebar">
134
<h3><a href="../index.html">Table of Contents</a></h3>
136
128
<li><a class="reference internal" href="#">Connection Pooling</a><ul>
137
129
<li><a class="reference internal" href="#connection-pool-configuration">Connection Pool Configuration</a></li>
138
130
<li><a class="reference internal" href="#switching-pool-implementations">Switching Pool Implementations</a></li>
158
<h4>Previous Topic</h4>
160
<a href="connections.html" title="previous chapter">Working with Engines and Connections</a>
164
<a href="event.html" title="next chapter">Events</a>
168
<h4>Quick Search</h4>
170
<form class="search" action="../search.html" method="get">
171
<input type="text" name="q" size="18" /> <input type="submit" value="Search" />
172
<input type="hidden" name="check_keywords" value="yes" />
173
<input type="hidden" name="area" value="default" />
179
158
<div id="docs-body" class="withsidebar" >
181
160
<div class="section" id="module-sqlalchemy.pool">
288
267
<span class="n">cursor</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s">"select foo"</span><span class="p">)</span></pre></div>
290
269
<p>The purpose of the transparent proxy is to intercept the <tt class="docutils literal"><span class="pre">close()</span></tt> call,
291
such that instead of the DBAPI connection being closed, it’s returned to the
270
such that instead of the DBAPI connection being closed, it is returned to the
293
272
<div class="highlight-python"><div class="highlight"><pre><span class="c"># "close" the connection. Returns</span>
294
273
<span class="c"># it to the pool.</span>
378
357
<h3>Disconnect Handling - Pessimistic<a class="headerlink" href="#disconnect-handling-pessimistic" title="Permalink to this headline">¶</a></h3>
379
358
<p>At the expense of some extra SQL emitted for each connection checked out from the pool,
380
359
a “ping” operation established by a checkout event handler
381
can detect an invalid connection before it’s used:</p>
360
can detect an invalid connection before it is used:</p>
382
361
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">exc</span>
383
362
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="kn">import</span> <span class="n">event</span>
384
363
<span class="kn">from</span> <span class="nn">sqlalchemy.pool</span> <span class="kn">import</span> <span class="n">Pool</span>