Python搁置模块问题 [英] Python shelve module question
问题描述
Python搁架模块是否内置任何保护措施,以确保两个进程不会同时写入文件?
Does the Python shelve module have any protection built in to make sure two processes aren't writing to a file at the same time?
推荐答案
The shelve module uses an underlying database package (such as dbm, gdbm or bsddb) .
限制 pragraph 说(我重点):
The restrictions pragraph says (my emphasis):
搁置模块不支持对搁置对象的并发读/写访问. (多个同时读取访问是安全的.)当程序有一个可供写的架子时,其他任何程序都不应将其打开以供读写.可以使用Unix文件锁定来解决此问题,但这在Unix版本之间有所不同,并且需要有关所使用的数据库实现的知识.
The shelve module does not support concurrent read/write access to shelved objects. (Multiple simultaneous read accesses are safe.) When a program has a shelf open for writing, no other program should have it open for reading or writing. Unix file locking can be used to solve this, but this differs across Unix versions and requires knowledge about the database implementation used.
结论:它取决于操作系统和基础数据库.为了使事情变得可移植,请不要基于并发.
Conclusion: it depends on OS and the underlying DB. To keep things portable, do not build on concurrency.
这篇关于Python搁置模块问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!