diff --git a/lower-constraints.txt b/lower-constraints.txt index 5a134ce2..9cc38298 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -22,7 +22,6 @@ keystoneauth1==3.4.0 linecache2==1.0.0 MarkupSafe==1.0 mccabe==0.2.1 -monotonic==0.6 mox3==0.20.0 msgpack-python==0.4.0 netaddr==0.7.18 diff --git a/oslo_service/__init__.py b/oslo_service/__init__.py index e6bdeccd..17ab9d3c 100644 --- a/oslo_service/__init__.py +++ b/oslo_service/__init__.py @@ -20,15 +20,6 @@ time = eventlet.patcher.original('time') LOG = logging.getLogger(__name__) -# TODO(bnemec): When we have a minimum dependency on a version of eventlet -# that uses monotonic by default, remove this monkey patching. -if hasattr(time, 'monotonic'): - # Use builtin monotonic clock, Python 3.3+ - _monotonic = time.monotonic -else: - import monotonic - _monotonic = monotonic.monotonic - def service_hub(): # NOTE(dims): Add a custom impl for EVENTLET_HUB, so we can @@ -36,7 +27,7 @@ def service_hub(): # uses time.time() and we need to use a monotonic timer # to ensure that things like loopingcall work properly. hub = eventlet.hubs.get_default_hub().Hub() - hub.clock = _monotonic + hub.clock = time.monotonic # get_default_hub() will return a hub that is supported on this platform hub.is_available = lambda: True return hub diff --git a/oslo_service/periodic_task.py b/oslo_service/periodic_task.py index ea3a9e14..51b5109b 100644 --- a/oslo_service/periodic_task.py +++ b/oslo_service/periodic_task.py @@ -16,16 +16,12 @@ import logging import random import six import time +from time import monotonic as now from oslo_service._i18n import _ from oslo_service import _options from oslo_utils import reflection -if hasattr(time, 'monotonic'): - now = time.monotonic -else: - from monotonic import monotonic as now # noqa - LOG = logging.getLogger(__name__) DEFAULT_INTERVAL = 60.0 diff --git a/oslo_service/tests/test_loopingcall.py b/oslo_service/tests/test_loopingcall.py index 537bd2c6..4192d086 100644 --- a/oslo_service/tests/test_loopingcall.py +++ b/oslo_service/tests/test_loopingcall.py @@ -11,13 +11,13 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import time from unittest import mock import eventlet from eventlet.green import threading as greenthreading from oslotest import base as test_base -import oslo_service from oslo_service import fixture from oslo_service import loopingcall @@ -38,7 +38,7 @@ class LoopingCallTestCase(test_base.BaseTestCase): def test_monotonic_timer(self): def _raise_it(): clock = eventlet.hubs.get_hub().clock - ok = (clock == oslo_service._monotonic) + ok = (clock == time.monotonic) raise loopingcall.LoopingCallDone(ok) timer = loopingcall.FixedIntervalLoopingCall(_raise_it) @@ -48,7 +48,7 @@ class LoopingCallTestCase(test_base.BaseTestCase): # Make sure that by default the oslo_service.service_hub() kicks in, # test in the main thread hub = eventlet.hubs.get_hub() - self.assertEqual(oslo_service._monotonic, + self.assertEqual(time.monotonic, hub.clock) def test_return_false(self): @@ -172,7 +172,7 @@ class DynamicLoopingCallTestCase(test_base.BaseTestCase): def test_monotonic_timer(self): def _raise_it(): clock = eventlet.hubs.get_hub().clock - ok = (clock == oslo_service._monotonic) + ok = (clock == time.monotonic) raise loopingcall.LoopingCallDone(ok) timer = loopingcall.DynamicLoopingCall(_raise_it)