Pyramid isn't opening the database connection, the SqlAlchemy pool is. On first glance, you're connecting to the database in your main(). This is guaranteed to create issues with SqlAlchemy's connection pool when you involve multiple workers/threads/processes. In some situations the connection gets reused by multiple processes, in others it gets lost.
The proper way to fix this is to call `engine.dispose()` [http://docs.sqlalchemy.org/en/latest/core/connections.html#engine-disposal] either immediately after you use it, or in a post-fork hook. I also don't see an add_finished_callback registered to call 'session.close() on every request (or at least the ones where you grab a dbsession), or the close() being called in any other way (like a tween). Between both of those traits, you're going to have a connection pool that constantly needs new connections (it has to wait for python's GC to clear out the connection), and might re-use existing connections unreliably. There could be other factors causing this too, but you should integrate a `dispose` after the app starts and add a utility to register a session.close() via add_finished_callback(). If that doesn't solve it, there are a lot of docs in SqlAlchemy on the connection pool specifics. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/d21f0d7e-f20c-4760-9e03-9e057dde376c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
