summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-05-12 07:54:14 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-05-12 07:54:14 -0400
commit7f08d8c93af1b574d1cc11af38baf26d9d59058f (patch)
tree8804a6160b2be55a4317bef70edb4e2a16b6e892
parent0604116814a862d4d9dbc1a8866a2a3b0126caf1 (diff)
downloadsqlalchemy-7f08d8c93af1b574d1cc11af38baf26d9d59058f.tar.gz
Add close_with_result to pessimistic connection example
For connectionless execution, the recipe here will fail unless the should_close_with_result flag is temporarily set to False. Change-Id: Ib77b4439e8361b24478108c413b1ba720a68350f Fixes: #3712
-rw-r--r--doc/build/core/pooling.rst8
1 files changed, 8 insertions, 0 deletions
diff --git a/doc/build/core/pooling.rst b/doc/build/core/pooling.rst
index 2855d1a95..65b5ca9cd 100644
--- a/doc/build/core/pooling.rst
+++ b/doc/build/core/pooling.rst
@@ -253,6 +253,11 @@ best way to do this is to make use of the
# we don't want to bother pinging on these.
return
+ # turn off "close with result". This flag is only used with
+ # "connectionless" execution, otherwise will be False in any case
+ save_should_close_with_result = connection.should_close_with_result
+ connection.should_close_with_result = False
+
try:
# run a SELECT 1. use a core select() so that
# the SELECT of a scalar value without a table is
@@ -272,6 +277,9 @@ best way to do this is to make use of the
connection.scalar(select([1]))
else:
raise
+ finally:
+ # restore "close with result"
+ connection.should_close_with_result = save_should_close_with_result
The above recipe has the advantage that we are making use of SQLAlchemy's
facilities for detecting those DBAPI exceptions that are known to indicate