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.
This commit is contained in:
Avery Pennarun 2018-10-30 01:08:21 +00:00
commit d143cca7da

View file

@ -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,6 +346,7 @@ class Lock:
_locks[self.fid] = 0
if self.owned:
self.unlock()
if self.lockfile is not None:
os.close(self.lockfile)
def trylock(self):