I’m writing a little web app with webpy, and I’m wondering if anyone has any information on a little problem I’m having.
I’ve written a little ORM system, and it seems to be working pretty well. Ideally I’d like to stitch it in with webpy, but it appears that just using it as is causes thread issues (DB connection is instantiated/accessed across thread boundaries, or so the exception states).
Does anyone know how I can (within the webpy) create my DB connection on the same thread as the rest of the page handling code will be?
We use SQLAlchemy with web.py and use hooks to create and close db connections per request. SQLAlchemy handles pooling, so not every connection is a tcp connection.
The thread local storage you want to use is web.ctx ie. any time you access web.ctx you only see properties set by that thread.
Our code looks something like this:
Replace Session with your db connection function and it should work fine for you.