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? If there are thread-sensitive situations, such 
as when using SQLite, perhaps attaching the clean-up logic to the callback 
on a weakref is the wrong thing to do? Not that I'm sure what the 
alternative would be...

Thanks,
Ben

-- 
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