2

Is it possible to share an in memory SQLite database using SQLAlchemy among multiple Python processes? All applications are reading and writing from/to it. If so, is it desirable?

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187
OrangeTux
  • 10,436
  • 7
  • 46
  • 72

1 Answers1

1

No, you cannot share an in-memory SQLite database between processes. An in-memory SQLite database is private to the connection that created it; even within the same process, a new connection to :memory: creates a new database. SQLAlchemy does not lift this limitation.

You can only share a file-based database. SQLite uses as system of locking to make that possible.

That said, SQLite is not the best choice for concurrent database access. A database using a separate server to manage multiple clients (such as MySQL or PostgreSQL) is a better choice if performance is an issue.

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187