From c1768401f7a47bd88c044687a00f2e139f1985b4 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Mon, 4 May 2020 17:02:44 -0500 Subject: [PATCH] Remove monotonic usage The monotonic package was needed for monotonic time operations when running under Python runtimes older than 3.3. Since we now only support versions higher than this, this third party package requirement can now be removed. Change-Id: I598530b3f417964ff697b48e681b135bd119ae81 Signed-off-by: Sean McGinnis --- lower-constraints.txt | 1 - .../_drivers/amqp1_driver/controller.py | 7 +------ .../_drivers/amqp1_driver/eventloop.py | 19 +++++++------------ requirements.txt | 1 - 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index db63fe6ac..b67442e30 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -32,7 +32,6 @@ linecache2==1.0.0 MarkupSafe==1.0 mccabe==0.2.1 mock==2.0.0 -monotonic==0.6 mox3==0.20.0 msgpack-python==0.4.0 netaddr==0.7.18 diff --git a/oslo_messaging/_drivers/amqp1_driver/controller.py b/oslo_messaging/_drivers/amqp1_driver/controller.py index 24dfc99ba..3e2f5bbf8 100644 --- a/oslo_messaging/_drivers/amqp1_driver/controller.py +++ b/oslo_messaging/_drivers/amqp1_driver/controller.py @@ -51,11 +51,6 @@ from oslo_messaging import exceptions from oslo_messaging.target import Target from oslo_messaging import transport -if hasattr(time, 'monotonic'): - now = time.monotonic -else: - from monotonic import monotonic as now # noqa - LOG = logging.getLogger(__name__) @@ -980,7 +975,7 @@ class Controller(pyngus.ConnectionEventHandler): # methods executed by Tasks created by the driver: def send(self, send_task): - if send_task.deadline and send_task.deadline <= now(): + if send_task.deadline and send_task.deadline <= time.monotonic(): send_task._on_timeout() return key = keyify(send_task.target, send_task.service) diff --git a/oslo_messaging/_drivers/amqp1_driver/eventloop.py b/oslo_messaging/_drivers/amqp1_driver/eventloop.py index b6ffe7286..7cfd2ea4e 100644 --- a/oslo_messaging/_drivers/amqp1_driver/eventloop.py +++ b/oslo_messaging/_drivers/amqp1_driver/eventloop.py @@ -35,18 +35,13 @@ import threading import time import uuid -if hasattr(time, 'monotonic'): - now = time.monotonic -else: - from monotonic import monotonic as now # noqa - LOG = logging.getLogger(__name__) def compute_timeout(offset): # minimize the timer granularity to one second so we don't have to track # too many timers - return math.ceil(now() + offset) + return math.ceil(time.monotonic() + offset) class _SocketConnection(object): @@ -75,7 +70,7 @@ class _SocketConnection(object): if self.socket: try: pyngus.read_socket_input(self.pyngus_conn, self.socket) - self.pyngus_conn.process(now()) + self.pyngus_conn.process(time.monotonic()) except (socket.timeout, socket.error) as e: # pyngus handles EAGAIN/EWOULDBLOCK and EINTER self.pyngus_conn.close_input() @@ -87,7 +82,7 @@ class _SocketConnection(object): if self.socket: try: pyngus.write_socket_output(self.pyngus_conn, self.socket) - self.pyngus_conn.process(now()) + self.pyngus_conn.process(time.monotonic()) except (socket.timeout, socket.error) as e: # pyngus handles EAGAIN/EWOULDBLOCK and EINTER self.pyngus_conn.close_output() @@ -213,7 +208,7 @@ class Scheduler(object): due = self._deadlines[0] if self._deadlines else None if due is None: return max_delay - _now = now() + _now = time.monotonic() if due <= _now: return 0 else: @@ -222,7 +217,7 @@ class Scheduler(object): def _process(self): """Invoke all expired callables.""" if self._deadlines: - _now = now() + _now = time.monotonic() try: while self._deadlines[0] <= _now: deadline = heapq.heappop(self._deadlines) @@ -376,7 +371,7 @@ class Thread(threading.Thread): # force select to return in time to service the next expiring timer if deadline: - _now = now() + _now = time.monotonic() timeout = 0 if deadline <= _now else (deadline - _now) else: timeout = None @@ -397,7 +392,7 @@ class Thread(threading.Thread): self._requests.process_requests() self._connection.read_socket() if pyngus_conn and pyngus_conn.deadline: - _now = now() + _now = time.monotonic() if pyngus_conn.deadline <= _now: pyngus_conn.process(_now) self._connection.write_socket() diff --git a/requirements.txt b/requirements.txt index ad19a3877..e8261a20d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,6 @@ oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.service!=1.28.1,>=1.24.0 # Apache-2.0 stevedore>=1.20.0 # Apache-2.0 debtcollector>=1.2.0 # Apache-2.0 -monotonic>=0.6;python_version<'3.3' # Apache-2.0 # for jsonutils six>=1.10.0 # MIT