[docs]classSoftFileLock(BaseFileLock):"""Simply watches the existence of the lock file."""def_acquire(self)->None:raise_on_not_writable_file(self.lock_file)ensure_directory_exists(self.lock_file)# first check for exists and read-only mode as the open will mask this case as EEXISTflags=(os.O_WRONLY# open for writing only|os.O_CREAT|os.O_EXCL# together with above raise EEXIST if the file specified by filename exists|os.O_TRUNC# truncate the file to zero byte)try:file_handler=os.open(self.lock_file,flags,self._context.mode)exceptOSErrorasexception:# re-raise unless expected exceptionifnot(exception.errno==EEXIST# lock already existor(exception.errno==EACCESandsys.platform=="win32")# has no access to this lock):# pragma: win32 no coverraiseelse:self._context.lock_file_fd=file_handlerdef_release(self)->None:assertself._context.lock_file_fdisnotNone# noqa: S101os.close(self._context.lock_file_fd)# the lock file is definitely not Noneself._context.lock_file_fd=Nonewithsuppress(OSError):# the file is already deleted and that's what we wantPath(self.lock_file).unlink()