[Twisted-Python] How to correctly run Sqlite with Twisted?

Goffi goffi at goffi.org
Tue Sep 19 14:59:08 MDT 2017


Hello,

I'm using Sqlite3 module through Twisted's enterpirse.adbapi, I create the 
ConnectionPool instance like this:

   self.dbpool = ConnectionPool("sqlite3", db_filename, 
check_same_thread=False)

You can see the code at https://repos.goffi.org/sat/file/tip/src/memory/sqlite.py

Sometime, the writing is failing with following exception:

  Failure instance: Traceback: <class 'sqlite3.OperationalError'>: database is 
locked

So I wonder if the database is correctly used, did anybody experienced 
something similar with Twisted and Sqlite ?

Should I just augment timeout as advised at https://stackoverflow.com/a/
8618328? Looks like more a workaround than a clean solution.

Python 2 documentation doesn't talk about check_same_thread argument, but 
Python 3 at https://docs.python.org/3.5/library/sqlite3.html#sqlite3.connect 
says that writing operation should be serialized by the user (I thought it was 
the default as said in https://sqlite.org/threadsafe.html), how should I 
achieve that?

Also PRAGMA are not working (specially "PRAGMA foreign_keys = ON"), I guess 
because of multi-threading, what is the good way to activate foreign_keys for 
all following request?

Thanks in advance

Goffi



More information about the Twisted-Python mailing list