On Mon, Feb 17, 2014 at 9:31 PM, Michael Bayer <mike...@zzzcomputing.com> wrote: > the Python DBAPI as you know returns a connection that's in a transaction. So > if you are using an environment that has zero tolerance for even two > statements in one transaction, you should turn on "autocommit" at the > psycopg2 level, using the "connection.autocommit" flag. you can achieve > this with an on-connect event, with some tricks currently needed to > absolutely force it as the first thing that happens (I need to either > document this or make a nicer API, but this works for now), like this: > > from sqlalchemy import event, create_engine > > eng = create_engine("postgresql+psycopg2://scott:tiger@localhost/test", > echo=True) > > @event.listens_for(eng, "first_connect", insert=True) > @event.listens_for(eng, "connect", insert=True) > def setup_autocommit(dbapi_conn, rec): > dbapi_conn.autocommit = True > > conn = eng.connect() > print conn.execute("select 1").fetchall()
This is exactly what I need, thanks. Furthermore, with psycopg2 level autocommit, I don't think I even need a second statement-based pool, it will decrease idle-in-transaction time on its own. In fact, I thought this is what execution_options(autocommit=True) did, though looking at the code, now I realize it wasn't. Many thanks :) PS: Yeah, I know I have to update to 8.x ;-) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.