Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignored missing lock file #797

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Ignored missing lock file #797

merged 1 commit into from
Sep 16, 2024

Conversation

nicolassidoux
Copy link
Collaborator

@nicolassidoux nicolassidoux commented Sep 9, 2024

FileLock Unix implementation for releasing the lock:

        def _release(self) -> None:
            # Do not remove the lockfile:
            #   https://github.com/tox-dev/py-filelock/issues/31
            #   https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
            fd = cast(int, self._context.lock_file_fd)
            self._context.lock_file_fd = None
            fcntl.flock(fd, fcntl.LOCK_UN)
            os.close(fd)

FileLock Windows implementation for releasing the lock:

        def _release(self) -> None:
            fd = cast(int, self._context.lock_file_fd)
            self._context.lock_file_fd = None
            msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
            os.close(fd)

            with suppress(OSError):  # Probably another instance of the application hat acquired the file lock.
                Path(self.lock_file).unlink()

TLDR: the Windows version of _release() deletes the lock file, while the Unix version doesn't. So on Windows the additional call of Path(lock_path).unlink() after exiting FileLock context causes an exception because the file is not present anymore.

Good thing is unlink() accepts the argument missing_ok=True. This argument makes unlink(missing_ok=True) not to throw an exception if the file is not found, resolving the problem.

@nicolassidoux nicolassidoux linked an issue Sep 9, 2024 that may be closed by this pull request
@github-actions github-actions bot added the bug Something isn't working label Sep 9, 2024
@Zethson
Copy link
Member

Zethson commented Sep 16, 2024

Great, thank you!

@Zethson Zethson merged commit 2525089 into main Sep 16, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First call to built-in datasets fails
2 participants