On Jun 10, 2010, at 2:54 PM, Vinay Sajip wrote:

> I'm getting the "SQLite objects created in a thread can only be used
> in that same thread." error when using a web application with mod_wsgi
> configured in daemon mode with processes=1, threads=15 on Ubuntu
> Karmic, using Python2.6.


> 
> When a GET request is received, a user is retrieved from an ID stored
> in the HTTP session - this uses a query attribute on the mapped class
> which is obtained using session_var.query_property(). All conventional
> stuff.

First off, the absolute recommended behavior for SQLite if a file-based 
database is to not use pooling.  I would suggest you use a NullPool to 
eliminate any connection pooling.  Some detail on this at 
http://www.sqlalchemy.org/docs/reference/dialects/sqlite.html#threading-behavior
 .   Seems like I mention it in the linked thread as well.

You then need to ensure no sqlalchemy-session-bound objects in your web 
application are shared between threads.  When you put things into your HTTP 
session, assuming its an in-memory HTTP session, make sure objects that go in 
there arent attached to a SQLAlchemy session.  Use expunge() or similar for 
this.  Calling remove() at the end of the request will work, except for the 
fact that a concurrent thread might be accessing the HTTP session before you 
get that far.    I would recommend using cookie based HTTP sessions in any case 
(see Beaker for this functionality).

> Using Mike Bayer's _threading_local patch in thread [1] made no
> difference.

That thread regarded someone using an extremely rare tool called PyISAPIe, 
which had threading bugs in it.  That doesn't apply to a basic mod_wsgi 
configuration.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.

Reply via email to