Python: Lock directory

前端 未结 4 495
-上瘾入骨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条回答
  •  醉梦人生
    2021-01-19 15:15

    I found an answer here: Python: Lock directory

    It is possible to lock a directory with this:

    fcntl.flock(self.dir_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
    

    Of course this is a lock which every code which plays in this game need to check first.

    AFAIK this is called "advisory lock".

提交回复
热议问题