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:56:40 -0400
commitc55ad969190016dfbeb1c033d123f105dc2e980b (patch)
tree113b36df9e4f1f1f3401e5cff63501661a806563
parent40b0e4b424c87adedfdf3bf968f3ee6851743fc2 (diff)
downloadsqlalchemy-c55ad969190016dfbeb1c033d123f105dc2e980b.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 (cherry picked from commit 7f08d8c93af1b574d1cc11af38baf26d9d59058f)
-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