I have a object that wraps all access to SQLAlchemy, let’s called it Wrapper. I use sqlalchemy.orm.scoped_session so that any session is local to the thread this class is in as per the documentation. Now, I have a Master thread that creates an instance of Wrapper. A few Slave threads are created by the Mater and passed a reference to the Wrapper.
When any Slave calls any SQLAlchemy called from within the Wrapper class, the following error is raised:
DB Exception raied: DB Error: (OperationalError) no such table:[...]
What am I doing wrong?
Should I create new instances of Wrapper for each Slave?
Edit: I am using a SQLite in memory database (mainly for testing) if that makes any difference. And the winner is: sqlite in memory cannot be shared between threads so I can pass an engine to the Wrapper as long as it is not an in memory one. Setting True to the verbose option is a very good debugging tool.
Yes, either create a Wrapper in each thread, or have the Wrapper maintain a pool of sessions.