From 63dd0eb8d705b42bc5e312b9141ba7c8d96ab717 Mon Sep 17 00:00:00 2001 From: tmaeno Date: Thu, 11 Jan 2024 17:36:21 +0100 Subject: [PATCH] rollback of utcnow changes --- pandacommon/pandalogger/LogWrapper.py | 4 ++-- pandacommon/pandamsgbkr/msg_bkr_utils.py | 5 ++--- pandacommon/pandautils/thread_utils.py | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pandacommon/pandalogger/LogWrapper.py b/pandacommon/pandalogger/LogWrapper.py index bc2c807..8391d74 100644 --- a/pandacommon/pandalogger/LogWrapper.py +++ b/pandacommon/pandalogger/LogWrapper.py @@ -9,7 +9,7 @@ class LogWrapper: def __init__(self, log, prefix="", lineLimit=100, monToken=None, seeMem=False, hook=None): # use timestamp as prefix if prefix is None: - self.prefix = datetime.datetime.now(datetime.timezone.utc).isoformat("/") + self.prefix = datetime.datetime.utcnow().isoformat("/") else: self.prefix = prefix # logger instance @@ -37,7 +37,7 @@ def keepMsg(self, msg): # keep max message depth if len(self.msg_buffer) > self.line_limit: self.msg_buffer.pop(0) - timeNow = datetime.datetime.now(datetime.timezone.utc) + timeNow = datetime.datetime.utcnow() self.msg_buffer.append("{0} : {1}".format(timeNow.isoformat(" "), msg)) def debug(self, msg): diff --git a/pandacommon/pandamsgbkr/msg_bkr_utils.py b/pandacommon/pandamsgbkr/msg_bkr_utils.py index 3b1047d..551db3f 100644 --- a/pandacommon/pandamsgbkr/msg_bkr_utils.py +++ b/pandacommon/pandamsgbkr/msg_bkr_utils.py @@ -17,7 +17,6 @@ from Queue import Empty, Queue import stomp - from pandacommon.pandalogger import logger_utils # logger @@ -720,7 +719,7 @@ def add_remover(self, headers, timeout): # unique id for each remover r_id = self.sub_id + "." + str(uuid.uuid4()) with self.remover_lock: - self.removers[r_id] = {"timeout": datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=timeout), "headers": copy.copy(headers)} + self.removers[r_id] = {"timeout": datetime.datetime.utcnow() + datetime.timedelta(seconds=timeout), "headers": copy.copy(headers)} # reconnect if necessary if self.got_disconnected: self.restart() @@ -734,7 +733,7 @@ def purge_removers(self): """ self.logger.debug("purging old removers") with self.remover_lock: - time_now = datetime.datetime.now(datetime.timezone.utc) + time_now = datetime.datetime.utcnow() n_old = len(self.removers) for r_id in list(self.removers): timeout = self.removers[r_id]["timeout"] diff --git a/pandacommon/pandautils/thread_utils.py b/pandacommon/pandautils/thread_utils.py index 573ccb5..0c0c27c 100644 --- a/pandacommon/pandautils/thread_utils.py +++ b/pandacommon/pandautils/thread_utils.py @@ -67,14 +67,14 @@ def __getitem__(self, item): def __setitem__(self, item, value): with self.lock: - dict.__setitem__(self, item, {"time_stamp": datetime.datetime.now(datetime.timezone.utc), "data": value}) + dict.__setitem__(self, item, {"time_stamp": datetime.datetime.utcnow(), "data": value}) # check data by taking freshness into account def __contains__(self, item): with self.lock: try: ret = dict.__getitem__(self, item) - if ret["time_stamp"] > datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(minutes=self.timeout): + if ret["time_stamp"] > datetime.datetime.utcnow() - datetime.timedelta(minutes=self.timeout): return True except Exception: pass