开发者

SQLAlchemy, sqlite and fork()

开发者 https://www.devze.com 2023-04-07 13:29 出处:网络
What is the best way to use fork() in a SQLAlchemy + sqlite project? The SQLAlchemy documentation mentions that one should call create_engine() in the child but doesn\'t mention any other caveats, of

What is the best way to use fork() in a SQLAlchemy + sqlite project?

The SQLAlchemy documentation mentions that one should call create_engine() in the child but doesn't mention any other caveats, of which I am sure there are plenty (write locks, busy_timeout, dispose/connection-issues, etc).

Would the d开发者_运维问答esign issue of whether to use transactions or scoped sessions matter?


SQLite does not support write concurrency so only one client can write to a single database at any point in time. With that constraint in place, the only gain you will get from using transactions is the ability to roll them back. If you plan to use multiple databases, make sure you don't drag yourself into a deadlock where two processes hold a transactional write lock in one database and try to simultaneously obtain one in the other.


sqlite will handle all of the database locking for you; this is not something that you can or should think about on the client side of the database connection.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号