On Thursday, December 27, 2012 10:22:08 PM UTC-3, Michael Bayer wrote:
>
>
> On Dec 27, 2012, at 6:28 PM, Diego Woitasen wrote:
>
> Hi,
>  I know that this was discussed several times in the past but I can't 
> solve the problem with the tip that I read in this list. Every morning my 
> application dies with the msg "MySQL has gone away". My app has different 
> modules (which are process) and this errors appears in the simplest one and 
> in the complex one too. There is no activity usually at night, specially in 
> one of the modules that has the issue more frequently.
>
> This lines setup the session:
>
> engine = create_engine(mysql_uri, pool_recycle=config.db_pool_recycle) # 
> Configure in 300 seconds right now.
> DBSession = scoped_session(sessionmaker(autocommit=False,
>                                     autoflush=False,
>                                     bind=engine))
>
> THe simplest module only do this with the DB:
>
>     try:
>         delivery = db.DBSession.query(db.Delivery).\
>                 filter(db.Delivery.id == delivery_cmsg.delivery_id).one()
>     except NoResultFound:
>         print 'WARN: invalid delivery ID: ' + 
> int(delivery_cmsg.delivery_id)
>         return
>     finally:
>         db.DBSession.commit()
>
>     print delivery.name, delivery.start, delivery.status
>
> And it has the issue every morning.
>
> I'm using SA 0.7.9 and MySQLdb 1.2.4c1.
>
> Is there a checklist of things to check that could cause this problem?
>
>
> so you've got pool_recycle, which will make sure the connection is 
> refreshed when checked out from the pool.  The other part is to make sure 
> that when the app is idle, you have actually checked all connections back 
> in.  So this means every Session has been committed, rolled back, or 
> closed, every Connection closed, every ResultProxy you might have gotten 
> from executing a statement is fully exhausted of its rows and/or closed, 
> and if you happen to be using the very old "thread local engine" system 
> (which I don't recommend) you'd also have committed/rolled back any 
> transaction there.
>
>
>
>

I'm back to this :)

My problem was that I'm not closing the session properly.  

My new question is... is there a way to autoclose the session? My example, 
at the end of the scope?

What's the recommend way to do this?

I've read the FAQ, but it's not very clear for me.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/NXOOxkeCEWMJ.
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