Detect and delete locked file in python

后端 未结 3 1803
感情败类
感情败类 2021-02-10 16:57

I want to detect whether a file is locked, using python on Unix. It\'s OK to delete the file, assuming that it helps detects whether the file was locked.

The file could

3条回答
  •  天命终不由人
    2021-02-10 17:28

    I tried to lock a file in mac and delete the same file in another terminal. It allows the file to be deleted.

    lock_file_path = "/tmp/lock.file"
    fd = open(lock_file_path,"w")
    fcntl.flock(fd.fileno(),LOCK_EX)
    while True:
        print("Locked")
    

提交回复
热议问题