Locking a file in Python

后端 未结 13 2403
悲&欢浪女
悲&欢浪女 2020-11-22 03:00

I need to lock a file for writing in Python. It will be accessed from multiple Python processes at once. I have found some solutions online, but most fail for my purposes as

13条回答
  •  -上瘾入骨i
    2020-11-22 03:56

    I have been looking at several solutions to do that and my choice has been oslo.concurrency

    It's powerful and relatively well documented. It's based on fasteners.

    Other solutions:

    • Portalocker: requires pywin32, which is an exe installation, so not possible via pip
    • fasteners: poorly documented
    • lockfile: deprecated
    • flufl.lock: NFS-safe file locking for POSIX systems.
    • simpleflock : Last update 2013-07
    • zc.lockfile : Last update 2016-06 (as of 2017-03)
    • lock_file : Last update in 2007-10

提交回复
热议问题