Python, SQLite and threading

前端 未结 6 1463
半阙折子戏
半阙折子戏 2020-12-29 00:03

I\'m working on an application that will gather data through HTTP from several places, cache the data locally and then serve it through HTTP.

So I was looking at the

6条回答
  •  一生所求
    2020-12-29 00:55

    Short answer: Don't use Sqlite3 in a threaded application.

    Sqlite3 databases scale well for size, but rather terribly for concurrency. You will be plagued with "Database is locked" errors.

    If you do, you will need a connection per thread, and you have to ensure that these connections clean up after themselves. This is traditionally handled using thread-local sessions, and is performed rather well (for example) using SQLAlchemy's ScopedSession. I would use this if I were you, even if you aren't using the SQLAlchemy ORM features.

提交回复
热议问题