Commit b4f89cd0 authored by Daniel Scheffler's avatar Daniel Scheffler

MultiSlotLock and MemoryReserver now hold a default Logger instance in case no...

MultiSlotLock and MemoryReserver now hold a default Logger instance in case no logger is passed. This makes the logger.close() call obsolete and fixes Test_DEM_Creator.test_index_mediator_query_equals_pgSQL_query().
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent de874973
Pipeline #16134 failed with stages
in 20 minutes and 11 seconds
......@@ -23,6 +23,8 @@ History
(relates to issue #103).
* Fixed issue #105 ('FileNotFoundError: Options file not found ...' when running run_gms.py -h after installing
gms_preprocessing from pip or conda-forge.)
* MultiSlotLock and MemoryReserver now hold a default Logger instance in case no logger is passed. This makes the
logger.close() call obsolete and fixes Test_DEM_Creator.test_index_mediator_query_equals_pgSQL_query().
0.18.11 (2020-11-03)
......
......@@ -33,6 +33,7 @@ from redis.exceptions import ConnectionError as RedisConnectionError
from retools.lock import Lock, LockTimeout
import functools
from psutil import virtual_memory
from logging import getLogger
from ..misc.logging import GMS_logger
from ..options.config import GMS_config as CFG
......@@ -55,8 +56,8 @@ To get a list of all currently set redis keys, run:
Then, to delete all currently set redis keys, run:
for i in list(sorted(conn.keys())):
k = i.decode('utf-8')
conn.delete(k)
k = i.decode('utf-8')
conn.delete(k)
"""
......@@ -65,7 +66,7 @@ class MultiSlotLock(Semaphore):
self.disabled = redis_conn is None or allowed_slots in [None, False]
self.namespace = name
self.allowed_slots = allowed_slots
self.logger = logger or GMS_logger("RedisLock: '%s'" % name)
self.logger = logger or getLogger("RedisLock: '%s'" % name)
if not self.disabled:
super(MultiSlotLock, self).__init__(client=redis_conn, count=allowed_slots, namespace=name, **kwargs)
......@@ -97,7 +98,6 @@ class MultiSlotLock(Semaphore):
def __exit__(self, exc_type, exc_val, exc_tb):
exitcode = super(MultiSlotLock, self).__exit__(exc_type, exc_val, exc_tb)
self.logger.close()
return exitcode
......@@ -181,15 +181,12 @@ class MemoryReserver(object):
self.disabled = redis_conn is None or CFG.disable_memory_locks or mem2lock_gb in [None, False]
self.mem2lock_gb = mem2lock_gb
self.max_usage = max_usage
self.logger = logger or getLogger("RedisLock: 'MemoryReserver'")
self.namespace = 'MemoryReserver'
self.client = redis_conn
self._waiting = False
self.mem_limit = int(virtual_memory().total * max_usage / 100 / 1024 ** 3)
if not self.disabled:
self.logger = logger or GMS_logger("RedisLock: 'MemoryReserver'")
self._waiting = False
@property
def mem_reserved_gb(self):
......@@ -321,9 +318,6 @@ class MemoryReserver(object):
def __exit__(self, exc_type, exc_val, exc_tb):
self.release()
if not self.disabled:
self.logger.close()
return True if exc_type is None else False
......
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