I'm getting an OperationalError: (OperationalError) database is locked
error when connection via SQLAlchemy in an IPython notebook instance and I'm not sure why.
I've written a Python interface to a SQLite database using SQLAlchemy and the Declarative Base syntax. I import the database models into an IPython notebook to explore the data. This worked just fine this morning. Here is the code:
from psf_database_interface import session, PSFTable
query = session.query(PSFTable).first()
But this afternoon after I closed my laptop with IPython running (it restarts the server just fine) I started getting this error. It's strange because I can still open the database from the SQLite3 command line tool and query data. I don't expect any other processes to be connecting to this database and running fuser
on the database confirms this. My application is not using any concurrent processes (in the code I've written, IDK if something is buried in SQLAlchemy or IPython), and even if it were I'm just doing a read operation, which SQLite does support concurrently.
I've tried restarting the IPython kernel as well as killing and restarting the IPython notebook server. I've tried creating a backup of the database and replacing the database with the backup as suggested here: https://stackoverflow.com/a/2741015/1216837. Lastly, out of desperation, I tried adding the following to see if I could clean out something stuck in the session somehow:
print session.is_active
session.flush()
session.close()
session.close_all()
print session.is_active
Which returns True
and True
. Any ideas?
Update: I can run the code snippet that is causing errors from a python file without any issues, the issue only occurs in IPython.