Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions ilock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,16 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if self._enter_count > 0:
return

if sys.platform.startswith('linux'):
# In Linux you can delete a locked file
os.unlink(self._filepath)

self._lockfile.close()

if sys.platform == 'win32':
# In Windows you need to unlock a file before deletion
try:
os.remove(self._filepath)
except WindowsError as e:
# Mute exception in case an access was already acquired (EACCES)
# and in more rare case when it was even already released and file was deleted (ENOENT)
if e.errno not in [errno.EACCES, errno.ENOENT]:
raise
try:
os.unlink(self._filepath)
except WindowsError as e:
# Mute exception in case an access was already acquired (EACCES)
# and in more rare case when it was even already released and file was deleted (ENOENT)
if e.errno not in [errno.EACCES, errno.ENOENT]:
raise
except FileNotFoundError:
# the file may already removed from another process.
# https://github.com/symonsoft/ilock/issues/4
pass