I am coding a little bit of server software for that personal utilization of several customers. Not 100s, not 1000's, but possibly 3-10 at any given time.
Becasue it is a threaded server, SQLite does not work. It gripes about threads such as this:
ProgrammingError: SQLite objects produced inside a thread are only able to be utilized for the reason that same thread.The item was produced in thread id 140735085562848 which is thread id 4301299712
Besides, they are saying SQLite is not ideal for concurrency anyhow.
Now since i have began dealing with Python 3 (and prefer to keep using it) I can not appear to obtain the MySQL module to operate correctly yet others appear equally frustrated.
For the reason that situation, can there be every other DB choice for Python 3 which i could consider?
First observe that sqlite is thread safe
$ python Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite >>> sqlite.threadsafety 1
Then just make certain you open a brand new handle towards the database in every thread.
I actually do this using thread local storage to cache the database handle so there's just one per thread. Something similar to this... (from the py2.5 prog - hopefully it'll use 3.!)
import threading class YourClass: def __init__(self): #... self.local = threading.local() # Thread local storage for db handles self.db_file = "/path/to/db" #... def db_open(self): if not getattr(self.local, "db", None): self.local.db = sqlite3.connect(self.db_file) return self.local.db
Used to do a port of psycopg2 to Python 3.
You can produce a new sqlite object in every thread, each utilizing the same database file. For such a small amount of customers you will possibly not run into the issues with concurrency, unless of course they all are conntacting it very heavily.
Surely a practical choice is to simply play one SQLite connection per thread.