Locking a file in Python

后端 未结 13 2381
悲&欢浪女
悲&欢浪女 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条回答
  •  情深已故
    2020-11-22 03:39

    There is a cross-platform file locking module here: Portalocker

    Although as Kevin says, writing to a file from multiple processes at once is something you want to avoid if at all possible.

    If you can shoehorn your problem into a database, you could use SQLite. It supports concurrent access and handles its own locking.

提交回复
热议问题