Session and "pool_recycle" option

Issue #3259 closed
theking-laptop created an issue

This is not issue, actually, it's a question. I suppose I have a global scoped session object to use in Pyramid web application.

DBSession = scoped_session(
                sessionmaker(
                    autoflush=False,
                    autocommit=False,
                    extension=ZopeTransactionExtension()
                    )
                )

I want to use pool_recycle option because if no activity in specific time, client will be closed automatically and an error MySQL Server has gone away will be thrown. But I wonder, this operation pings to MySQL server only, that means current session if not be committed still remains or this operation drops everything such as connection, engine, etc... including all sessions?

This aspect is very important for web application, so I really want to know exact answer. I could not find this information in documentation.

Comments (2)

  1. Mike Bayer repo owner

    it's documented here. I've boldfaced the parts that should answer your question:

    http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html#setting-pool-recycle

    Above, any DBAPI connection that has been open for more than one hour will be invalidated and replaced, upon next checkout. Note that the invalidation only occurs during checkout - not on any connections that are held in a checked out state. pool_recycle is a function of the Pool itself, independent of whether or not an Engine is in use.

    if a Session is held open in a transaction for 8 hours, pool recycle is not going to help with that. Sessions should not be used in this manner.

    Any further questions please use the mailing list, thanks!

  2. Log in to comment