Hi, I'm hoping someone can help me with properly configuring a session/ transactions for multiple uses as I haven't been able to get it quite right.
I've created a python module to contain my model classes and a connection class. This module wil be imported by both single-use scripts (run, then quit), long-running background scripts (run passively while waiting for a new event), and imported into a TurboGears app. I'm using PostgreSQL 8.4, SQLAlchemy 0.5.5, and TurboGears 2.0. After getting different types of transaction errors, e.g. > InternalError: (InternalError) current transaction is aborted, > commands ignored until end of transaction block > InvalidRequestError: Can't reconnect until invalid transaction is > rolled back" > "A transaction is already begun. Use subtransactions=True " > sqlalchemy.exc.InvalidRequestError: A transaction is already begun. > Use subtransactions=True to allow subtransactions. I settled on this in my db connection module, which is called by all my scripts: class MyDatabase: def __init__(self, database_connection_string=None): self.database_connection_string = database_connection_string self.engine = create_engine(self.database_connection_string, echo=False) self.metadata = MetaData() self.metadata.bind = self.engine try: db # singleton except NameError: db = MyDatabase() engine = db.engine metadata = db.metadata Session = scoped_session(sessionmaker(bind=engine, autocommit=True, autoflush=False)) Then in each script I import this module, create a new session: session = Session() and query like this: if session.autocommit: session.begin() <do stuff that modifies the db, i.e. not just select statements> session.commit() I was hoping this is fairly bullet-proof, but unfortunately my TurboGears app still hangs (with no error messages) after running for some period of time, though I think it hangs when multiple queries hit the database at the same time. I'm suspecting some kind of deadlock, but that's just a guess. I'm at a loss as to where the problem lies, but I wanted to check with the experts here that I'm using SA appropriately. Any help/suggestions greatly appreciated. Cheers, Demitri --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. 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 -~----------~----~----~----~------~----~------~--~---