SQLAlchemy 是否可以在多个 Python 进程之间共享 SQLite 数据库? [英] Is it possible with SQLAlchemy to share SQLite database among multiple Python processes?

查看:51
本文介绍了SQLAlchemy 是否可以在多个 Python 进程之间共享 SQLite 数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在多个 Python 进程之间使用 SQLAlchemy 共享内存中的 SQLite 数据库?所有应用程序都在读取和写入它.如果是这样,是否可取?

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?

推荐答案

不,您不能在进程之间共享内存中的 SQLite 数据库.内存中的 SQLite 数据库是创建它的连接私有的;即使在同一个进程中,到 :memory: 的新连接也会创建一个新数据库.SQLAlchemy 没有解除这个限制.

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.

您只能共享基于文件的数据库.SQLite 使用 锁定系统 使之成为可能.

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

也就是说,SQLite 不是并发数据库访问的最佳选择.如果性能有问题,使用单独的服务器来管理多个客户端(例如 MySQL 或 PostgreSQL)的数据库是更好的选择.

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.

这篇关于SQLAlchemy 是否可以在多个 Python 进程之间共享 SQLite 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆