From d143cca7dad44d65eeb330f3a243f1d839201db4 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 30 Oct 2018 01:08:21 +0000 Subject: [PATCH] class Lock: set lockfile = None before trying to open a file. In case the open causes a delay and we got a KeyboardInterrupt, this prevents a weird error from the destructor about an uninitialized variable. --- state.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/state.py b/state.py index 354a5b2..7f24728 100644 --- a/state.py +++ b/state.py @@ -335,6 +335,7 @@ class Lock: def __init__(self, fid): self.owned = False self.fid = fid + self.lockfile = None self.lockfile = os.open(os.path.join(vars.BASE, '.redo/lock.%d' % fid), os.O_RDWR | os.O_CREAT, 0666) close_on_exec(self.lockfile, True) @@ -345,7 +346,8 @@ class Lock: _locks[self.fid] = 0 if self.owned: self.unlock() - os.close(self.lockfile) + if self.lockfile is not None: + os.close(self.lockfile) def trylock(self): assert(not self.owned)