Skip to content

Commit 65e26c6

Browse files
authored
Fix lockfile logic (#3648)
1 parent 73490de commit 65e26c6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/windows/main_window.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -284,31 +284,33 @@ def create_lock_file(self):
284284
self.clear_all_thumbnails()
285285

286286
# Write lock file (try a few times if failure)
287-
attempts = 5
288-
while attempts > 0:
287+
for attempt in range(5):
289288
try:
290289
# Create lock file
291290
with open(lock_path, 'w') as f:
292291
f.write(lock_value)
292+
log.debug("Wrote value {} to lock file {}".format(
293+
lock_value, lock_path))
293294
break
294-
except Exception:
295-
log.debug('Failed to write lock file (attempt: %s)' % attempts)
296-
attempts -= 1
295+
except OSError:
296+
log.debug('Failed to write lock file (attempt: {})'.format(
297+
attempt), exc_info=1)
297298
sleep(0.25)
298299

299300
def destroy_lock_file(self):
300301
"""Destroy the lock file"""
301302
lock_path = os.path.join(info.USER_PATH, ".lock")
302303

303304
# Remove file (try a few times if failure)
304-
attempts = 5
305-
while attempts > 0:
305+
for attempt in range(5):
306306
try:
307307
os.remove(lock_path)
308+
log.debug("Removed lock file {}".format(lock_path))
308309
break
309-
except Exception:
310-
log.debug('Failed to destroy lock file (attempt: %s)' % attempts)
311-
attempts -= 1
310+
except FileNotFoundError:
311+
break
312+
except OSError:
313+
log.debug('Failed to destroy lock file (attempt: %s)' % attempt, exc_info=1)
312314
sleep(0.25)
313315

314316
def tail_file(self, f, n, offset=None):

0 commit comments

Comments
 (0)