aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-09-14 16:13:05 +0200
committerAnton Khirnov <anton@khirnov.net>2022-09-14 16:13:39 +0200
commit2e5e247801a313603894529d0b44ca40f04d931e (patch)
tree93651b0716b3070b39afdb122cc867106b053c29
parent8ce1ed62c93381f17fea61b207d8eb89a3c4c0d8 (diff)
Use the exit stack for releasing the state dir lock.
-rwxr-xr-xfshare.py3
1 files changed, 1 insertions, 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)