Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible with SQLAlchemy to share SQLite database among multiple Python processes?

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?

like image 486
OrangeTux Avatar asked Mar 31 '26 13:03

OrangeTux


1 Answers

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.

like image 182
Martijn Pieters Avatar answered Apr 03 '26 03:04

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!