Can two processes access in-memory (:memory:) sqlite database concurrently?

前端 未结 2 592
梦毁少年i
梦毁少年i 2020-12-24 14:42

Is it possible to access database in one process, created in another? I tried:

IDLE #1

import sqlite3
conn = sqlite3.connect(\':         


        
2条回答
  •  没有蜡笔的小新
    2020-12-24 14:59

    No, they cannot ever access the same in-memory database from different processes Instead, a new connection to :memory: always creates a new database.

    From the SQLite documentation:

    Every :memory: database is distinct from every other. So, opening two database connections each with the filename ":memory:" will create two independent in-memory databases.

    This is different from an on-disk database, where creating multiple connections with the same connection string means you are connecting to one database.

    Within one process it is possible to share an in-memory database if you use the file::memory:?cache=shared URI:

    conn = sqlite3.connect('file::memory:?cache=shared', uri=True)
    

    but this is still not accessible from other another process.

提交回复
热议问题