From: Mike Bayer Date: Thu, 12 May 2016 11:54:14 +0000 (-0400) Subject: Add close_with_result to pessimistic connection example X-Git-Tag: rel_1_1_0b1~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f08d8c93af1b574d1cc11af38baf26d9d59058f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 --- diff --git a/doc/build/core/pooling.rst b/doc/build/core/pooling.rst index 2855d1a952..65b5ca9cd0 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