On Wed, Aug 24, 2011 at 9:49 PM, Michael Bayer <mike...@zzzcomputing.com> wrote:
>
> On Aug 23, 2011, at 11:21 PM, limodou wrote:
>
>> On Sat, Oct 23, 2010 at 9:22 PM, Michael Bayer <mike...@zzzcomputing.com> 
>> wrote:
>>>
>>> pool recycle means a connnection that is 3600 seconds old will be thrown 
>>> away.   does not help with reconnects.
>>>
>>> When a "server gone away" error is detected, the entire connection pool is 
>>> thrown away and rebuilt.  So assuming one engine, you'd get this error once 
>>> for each connection that is still checked out and attempts a new operation. 
>>>  Subsequent transactions will proceed since the pool has been rebuilt.
>>>
>>> There was also a Mysql-reconnect bug fixed in 0.6.3 where previous versions 
>>> might have impacted this.
>>>
>>
>> I want to know if this means that the first transaction will still be
>> failed, and others will be successful?
>
> When the error is received, whatever transactional state has occurred on that 
> connection is gone - however, if you're getting this error on the very first 
> moment the connection is used, there's no state on the connection in any case.
>
>
>> And sqlalchemy can automatically rebuild at the time the error occured
>> but not the next time?
>
> Not sure what the question is here.  You can call engine.dispose() at any 
> time to rebuild the connection pool completely, if you were building an 
> approach to "ping" the connection ahead of time perhaps.
>
>

finally I found the problem. In my case I build my own ORM based on
sqlalchemy, I call it "uliorm". And it only use base select, update,
insert, delete statements. And in order to keep the whole process can
share the same connection object, I used the
engin.contextual_connect() to get the default connection, and my logic
same like this:

db = create_engine(xxx, pool_recycle=7200)
conn = db.contextual_connect()
db.begin()
try:
    try:
        db.execute(yyyy)
        db.commit()
    except:
        db.rollback()
finally:
    conn.close()

But it seems that the conn is not close correctly, so the pool will
not recycle it.

And I changed my underliying connection process code, I built the
connection object in a Begin() function, and stored it to a
threading.local() object. And I also provide Commit() and Rollback()
functions. So I gave up the contextual_connect(). And the result seems
right now.

-- 
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://code.google.com/p/uliweb/
My Blog: http://hi.baidu.com/limodou

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to