Streamlined the lock check

This commit is contained in:
Joar Wandborg 2013-12-09 18:04:14 +01:00
parent 222ef8b421
commit 51fdc7206b

View file

@ -23,15 +23,20 @@ class Ledger:
@contextmanager @contextmanager
def locked_process(self): def locked_process(self):
if self.locked: if self.locked:
_log.warning('Process is already locked') raise RuntimeError('The process has already been locked,'
for i in range(1, 5): ' something\'s out of order.')
if i > 4:
# XXX: This code has no purpose in a single-threaded process
timout = 5 # Seconds
for i in range(1, timeout + 2):
if i > timeout:
raise RuntimeError('Ledger process is already locked') raise RuntimeError('Ledger process is already locked')
if not self.locked: if not self.locked:
break break
else: else:
_log.info('Waiting for one second... %d/%d', i, 5) _log.info('Waiting for one second... %d/%d', i, timeout)
time.sleep(1) time.sleep(1)