Skip to content

Catching known errors when opening/closing files#9

Open
gohar94 wants to merge 1 commit intosymonsoft:masterfrom
gohar94:master
Open

Catching known errors when opening/closing files#9
gohar94 wants to merge 1 commit intosymonsoft:masterfrom
gohar94:master

Conversation

@gohar94
Copy link

@gohar94 gohar94 commented Sep 2, 2020

On Windows, when opening a file which is held by another process, open call throws an exception (which is expected) - putting that in try/except.

On Linux, when closing a file that might have been closed by another process, unlink call throws an exception (which is expecting) - putting that in try/except.

@Cologler
Copy link

On my windows 10 PC, open a locked file does not raises any errors:

image

It raises a PermissionError only if I try to write some data into the locked file and flush it.

os.unlink(self._filepath)
try:
os.unlink(self._filepath)
except FileNotFoundError:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change that I want to add too.
In rare cases that happen from time to time, its happen.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explained why this wouldn't work in #7 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments