On 9/11/15 1:55 PM, Ben Sizer wrote:
I'm using SQLAlchemy 1.0.8 with an SQLite file-based database, running as part of a Flask-based server, and getting some strange results.

I'm seeing this exception raised:

ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 8088 and this is thread id 8672

The place where the exception is raised is in _finalize_fairy in pool.py, and that's being called from the lambda in pool.py line 491. That in turn is getting invoked from a completely unrelated piece of code, implying that this is perhaps just coming off the back of a Python garbage collection cycle or similar. The pool type at the time the exception is raised is a NullPool object, but obviously _finalize_fairy is getting called at an unexpected time when some of the operations are not valid.

This only happens when I don't explicitly close a session, which I accept is a bug in my own code. I've fixed that so I don't trigger this behaviour again. But is it correct (and safe) for _finalize_fairy to be called from arbitrary threads like this?
first off, this is an artificial limitation in the pysqlite driver that can be disabled at the driver level if need be. No other driver disallows even calling .close() from another thread. The error here is within a weakref callback so I'm assuming it's only emitted as a warning.

secondly, what alternative behavior would you propose? Maybe at this point we should *always* be emitting a warning when a weakref handler ends up closing the connection.



 Not that I'm sure what the alternative would be...

oh. Well there's your answer! our choices are 1. do nothing 2. use garbage collection. 1. do nothing might be an actual option considering that DBAPIs should be closing out their resources when their connections are garbage collected, but I can imagine that not every DBAPI does this very well.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to