python - Doing threading with sqlalchemy properly? -


i have multi threaded application treads work on objects fetched using sqlalchemy. objects put in thread queue threads poll from.

in main thread doing this:

feeds = db_session.query(feed).filter(feed.last_checked <= int(update_time)).all() feed in feeds:     self.feed_q.put(feed) 

and in threads updates feed objects, , keep getting these exceptions when doing updates:

programmingerror: (programmingerror) (2014, "commands out of sync; can't run command now")  statementerror: can't reconnect until invalid transaction rolled (original cause: invalidrequesterror: can't reconnect until invalid transaction rolled back) 

i understand has todo threads sharing same db session, don't know how fix this.

each thread should have separate database session. you're creating object that's stored in db_session somewhere, perhaps this:

db_session = session() 

essentially, need each thread have own db_session.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -