From 2e5e247801a313603894529d0b44ca40f04d931e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 14 Sep 2022 16:13:05 +0200 Subject: Use the exit stack for releasing the state dir lock. --- fshare.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fshare.py b/fshare.py index 6bf4f0c..5e48e94 100755 --- a/fshare.py +++ b/fshare.py @@ -392,6 +392,7 @@ with contextlib.ExitStack() as stack: except BlockingIOError: logger.error('The state directory is already locked by another process') sys.exit(1) + stack.callback(fcntl.flock, state_dir_fd, fcntl.LOCK_UN) try: # read the state file @@ -404,5 +405,3 @@ with contextlib.ExitStack() as stack: except StateCorruptError: logger.error('Corrupted state file') sys.exit(1) - finally: - fcntl.flock(state_dir_fd, fcntl.LOCK_UN) -- cgit v1.2.3