Commit 8294f8a5 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fix for locking processes due to race conditions.

parent 1e39f7ad
......@@ -7,6 +7,7 @@ from redis.exceptions import ConnectionError as RedisConnectionError
import logging
import functools
import re
import random
from ..misc.logging import GMS_logger
from ..options.config import GMS_config as CFG
......@@ -34,10 +35,10 @@ class MultiSlotLock(Lock):
if allowed_threads and redis_conn:
logged = False
while True:
time.sleep(random.uniform(0, 0.5)) # avoids race conditions in case multiple tasks are waiting
name_free_slot = self.get_free_slot_name()
if not name_free_slot:
if not name_free_slot:
if not logged:"Waiting for free '%s' lock." %
logged = True
......@@ -68,7 +69,9 @@ class MultiSlotLock(Lock):
while not self._acquired:
# print('Trying to acquire %s.' % self.final_name.split('GMS_%s__' % CFG.ID)[1])
self._acquired = super(MultiSlotLock, self).acquire(blocking=blocking, timeout=timeout)
# print("Acquired lock '%s'." % self.final_name.split('GMS_%s__' % CFG.ID)[1])
except AlreadyAcquired:
# this happens in case the lock has already been acquired by another instance of MultiSlotLock due
# to a race condition (time gap between finding the free slot and the call of self.acquire())
......@@ -76,6 +79,8 @@ class MultiSlotLock(Lock):
self.__init__(, allowed_threads=self.allowed_threads, logger=self.logger,
# print(self.final_name.split('GMS_%s__' % CFG.ID)[1], self._acquired)
if self._acquired:"Acquired lock '%s'." % self.final_name.split('GMS_%s__' % CFG.ID)[1])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment