SQLite3 and Multiprocessing

前端 未结 4 1719
南笙
南笙 2021-01-05 09:26

I noticed that sqlite3 isn´t really capable nor reliable when i use it inside a multiprocessing enviroment. Each process tries to write some data into the same database, so

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-05 10:04

    First of all, there's a difference between multiprocessing (multiple processes) and multithreading (multiple threads within one process).

    It seems that you're talking about multithreading here. There are a couple of caveats that you should be aware of when using SQLite in a multithreaded environment. The SQLite documentation mentions the following:

    • Do not use the same database connection at the same time in more than one thread.
    • On some operating systems, a database connection should always be used in the same thread in which it was originally created.

    See here for a more detailed information: Is SQLite thread-safe?

提交回复
热议问题