-
Notifications
You must be signed in to change notification settings - Fork 685
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
Fix WindowsError/OSError in singleton #10037
Open
dreamscached
wants to merge
1
commit into
Monika-After-Story:content
Choose a base branch
from
dreamscached:bugfix/singleton-racecond
base: content
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of the try..except makes this check redundant. Remove it and de-indent the try..except block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is not. We have already discussed this with @Booplicate and came to the conclusion this solves an issue some players may have when due to race condition file no longer exists after
os.path.exists
check, which causes an unnecessary error screen.try/except is used to catch this race condition caused error, so we can re-verify the existence of that file and throw an error if it still there and was not removed by another instance that beat this instance to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This smells like some sort of global state to me, but I'm admittedly unfamiliar with this codebase. Are you certain this instance should handle the lock file's deletion in that case?
At any rate, you already end up checking twice in the try..except alone. The
.unlink()
attempt is the implied check and a second one to handle the race condition happens in theexcept
block. Is theif
I marked really needed at this point, since all it's doing is "if this exists, check if it exists while I delete it, then check again if exceptions occur"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is why it's called singleton pattern, you can't do singleton without a global state.
The comment above the line you selected explains why we're trying to delete it.
Technically, you are correct, the system will check if the file exists when executing the
unlink
os call. However the check ensures that the file was present before the call tounlink
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well yes, it is a global state, we're talking about a lock file that is used to ensure only one instance of an entire application runs.
I did suggest to leave it just as
os.unlink
but was told it shouldn't remove this file for no reason (and that the preliminary check is necessary.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, however the purpose of try..except is also to cut down on preliminary checks where possible. This seems to be one of the cases where it is possible.
Makes sense, yes. Alternatively, I wonder if one could query the list of running processes and abort execution in case another MAS is already running, but I'm unfamiliar with Windows' way of doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel like changing existing code to be more of a cross-platform nightmare than it already is unless there's a strong argument for it.