Thank you for your suggestions honestly that had been bothering me too. I 
removed the tween from the code completly an in its place I added a request 
method of the same name as the database proxy object which opens a 
connection and then registers a final_callback method to close the 
connection. I like this in that it is cleaner in not opening a database 
connection if its not needed, but it does require you to explicily open a 
connetion rather then having one magicaly availabe to use. 

On Monday, July 20, 2015 at 2:48:29 PM UTC-4, Jonathan Vanasco wrote:
> I'm not sure what `request.peewee_dbs()[db].connect()` does, but I would 
> probably recommend against this db setup pattern that you're using.  By 
> doing this in a tween, every request that pyramid handles will do a 
> connect/disconnect to all the databases you defined.
> One of the more popular patterns to implement db connections is something 
> like this:
> - `add_request_method` provides an object that either returns an database 
> connection, or creates a new one.
> - if you create a new connection, it registers a 'db.close()' via 
> `add_finished_callback`
> this way you only connect as needed, and disconnect to actually connected 
> databases.

You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
For more options, visit

Reply via email to