peewee.OperationalError: database is locked using threadlocals and SqliteDatabase
I'm almost sure I fixed the problem [here](https://github.com/cryzed/Feedbuffer/commit/3b29434de92c8d0c47b90761858239ee1df08cd8). I'm just speculating, but I think the problem arose because I created the CherryPy server object in a [different thread](https://github.com/cryzed/Feedbuffer/commit/3b29434de92c8d0c47b90761858239ee1df08cd8#diff-5bc02cefb3ea9e27f1a6776eabd1935dL20) (main thread) instead of within the spawned thread. I also had to change the generator expression [here](https://github.com/cryzed/Feedbuffer/commit/3b29434de92c8d0c47b90761858239ee1df08cd8#diff-91c7a2706bca60a3f59aefad6b396b0eL32).

Now everything works without issues and it's reproducible -- reverting those changes leads to the aforementioned problems again and even slows everything down considerably. In the end I think it might be, because I am passing objects not local to the thread around, but I'd be lying if I said that I knew exactly what's going on. Maybe you have some input?

Thanks for peewee,
Chris
 I'm not sure about your application or anything specifically you may be encountering, but what I can tell you is:
- sqlite enforces a _global database lock_ when you write to the db.
- multi-threaded apps need to be careful about serializing writes or correctly handling "busy" errors.
- using peewee with threadsafe=True is the default for a long time. all it means is you get a connection per thread, but those threads/connections can still contend for write locks.

Hey, I recently made this: [Feedbuffer](https://github.com/cryzed/Feedbuffer) and decided to use peewee for the database interface. I know it's not really your task to review my code, but I feel my problem would be easiest to explain if I linked you the file that manages the database communication [here](https://github.com/cryzed/Feedbuffer/blob/master/feedbuffer/database.py).

The thread architecture of the whole thing looks as follows: A CherryPy (webserver) instance is started in its own thread, which may spawn more threads (IIRC up to 10 more in the default configuration) to handle requests. Additionally I am using a ThreadPoolExecutor with 5 up to 40 workers, depending on the system the script is running on.

The problem occurs when I try to update many new feeds at once by using my RSS reader (imagine ~200 feeds with 10~ connections asking for updates). What puzzles me is that I am getting a "database is locked" error -- I was under the assumption that this could be entirely avoided by using `threadlocals=True` and instructing peewee with that to manage a single connection per thread. Am I doing something in my code that would require this mechanism to fail? Are those too many threads for sqlite to handle?

Some advice would be great.
