Python: Lock directory

前端 未结 4 501
-上瘾入骨i
-上瘾入骨i 2021-01-19 14:51

AFAIK this code can be used to lock a directory:

class LockDirectory(object):
    def __init__(self, directory):
        assert os.path.exists(directory)
            


        
4条回答
  •  梦毁少年i
    2021-01-19 15:15

    I would suggest you go with a simple lock file. As the question in the comment (How to lock a directory between python processes in linux?) suggests, there is no locking mechanism for directories, as opposed to files.
    Lock files are used left and right on Linux, they are very transparent and easy to debug, so I would just go with that.
    I am waiting to be challenged on this however!

提交回复
热议问题