[PATCH] Remove unnecessary time.monotonic() compat

Michał Górny <[email protected]>
Newsgroups gmane.linux.gentoo.portage.devel
Message-ID <[email protected]>
time.monotonic() is available since py3.3, so there's no need for
the compat anymore.

Signed-off-by: Michał Górny <[email protected]>
---
 lib/portage/dbapi/vartree.py                 |  7 ++--
 lib/portage/tests/util/futures/test_retry.py |  8 ++---
 lib/portage/util/_eventloop/EventLoop.py     |  6 ++--
 lib/portage/util/monotonic.py                | 34 --------------------
 4 files changed, 10 insertions(+), 45 deletions(-)
 delete mode 100644 lib/portage/util/monotonic.py

diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py
index 3687b471b..80ca0ab80 100644
--- a/lib/portage/dbapi/vartree.py
+++ b/lib/portage/dbapi/vartree.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2019 Gentoo Authors
+# Copyright 1998-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import division, unicode_literals
@@ -36,7 +36,6 @@ portage.proxy.lazyimport.lazyimport(globals(),
 	'portage.util.install_mask:install_mask_dir,InstallMask,_raise_exc',
 	'portage.util.listdir:dircache,listdir',
 	'portage.util.movefile:movefile',
-	'portage.util.monotonic:monotonic',
 	'portage.util.path:first_existing,iter_parents',
 	'portage.util.writeable_check:get_ro_checker',
 	'portage.util._xattr:xattr',
@@ -3616,7 +3615,7 @@ class dblink(object):
 			symlink_collisions = []
 			destroot = self.settings['ROOT']
 			totfiles = len(file_list) + len(symlink_list)
-			previous = monotonic()
+			previous = time.monotonic()
 			progress_shown = False
 			report_interval = 1.7  # seconds
 			falign = len("%d" % totfiles)
@@ -3625,7 +3624,7 @@ class dblink(object):
 			for i, (f, f_type) in enumerate(chain(
 				((f, "reg") for f in file_list),
 				((f, "sym") for f in symlink_list))):
-				current = monotonic()
+				current = time.monotonic()
 				if current - previous > report_interval:
 					showMessage(_("%3d%% done,  %*d files remaining ...\n") %
 							(i * 100 / totfiles, falign, totfiles - i))
diff --git a/lib/portage/tests/util/futures/test_retry.py b/lib/portage/tests/util/futures/test_retry.py
index 7a1e76280..4530bba83 100644
--- a/lib/portage/tests/util/futures/test_retry.py
+++ b/lib/portage/tests/util/futures/test_retry.py
@@ -1,4 +1,4 @@
-# Copyright 2018 Gentoo Foundation
+# Copyright 2018-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 try:
@@ -12,6 +12,7 @@ except ImportError:
 	import dummy_threading as threading
 
 import sys
+import time
 
 from portage.tests import TestCase
 from portage.util._eventloop.global_event_loop import global_event_loop
@@ -19,7 +20,6 @@ from portage.util.backoff import RandomExponentialBackoff
 from portage.util.futures import asyncio
 from portage.util.futures.retry import retry
 from portage.util.futures.executor.fork import ForkExecutor
-from portage.util.monotonic import monotonic
 
 
 class SucceedLaterException(Exception):
@@ -31,12 +31,12 @@ class SucceedLater(object):
 	A callable object that succeeds some duration of time has passed.
 	"""
 	def __init__(self, duration):
-		self._succeed_time = monotonic() + duration
+		self._succeed_time = time.monotonic() + duration
 
 	def __call__(self):
 		loop = global_event_loop()
 		result = loop.create_future()
-		remaining = self._succeed_time - monotonic()
+		remaining = self._succeed_time - time.monotonic()
 		if remaining > 0:
 			loop.call_soon_threadsafe(lambda: None if result.done() else
 				result.set_exception(SucceedLaterException(
diff --git a/lib/portage/util/_eventloop/EventLoop.py b/lib/portage/util/_eventloop/EventLoop.py
index ffd12cff9..a3bea97aa 100644
--- a/lib/portage/util/_eventloop/EventLoop.py
+++ b/lib/portage/util/_eventloop/EventLoop.py
@@ -1,4 +1,4 @@
-# Copyright 1999-2018 Gentoo Foundation
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from __future__ import division
@@ -11,6 +11,7 @@ import os
 import select
 import signal
 import sys
+import time
 import traceback
 
 try:
@@ -37,7 +38,6 @@ portage.proxy.lazyimport.lazyimport(globals(),
 )
 
 from portage.util import writemsg_level
-from portage.util.monotonic import monotonic
 from ..SlotObject import SlotObject
 from .PollConstants import PollConstants
 from .PollSelectAdapter import PollSelectAdapter
@@ -887,7 +887,7 @@ class EventLoop(object):
 		epoch, precision, accuracy and drift are unspecified and may
 		differ per event loop.
 		"""
-		return monotonic()
+		return time.monotonic()
 
 	def call_later(self, delay, callback, *args, **kwargs):
 		"""
diff --git a/lib/portage/util/monotonic.py b/lib/portage/util/monotonic.py
deleted file mode 100644
index e50564851..000000000
--- a/lib/portage/util/monotonic.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright 2018 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-__all__ = ['monotonic']
-
-import time
-try:
-	import threading
-except ImportError:
-	import dummy_threading as threading
-
-monotonic = getattr(time, 'monotonic', None)
-
-if monotonic is None:
-	def monotonic():
-		"""
-		Emulate time.monotonic() which is available in Python 3.3 and later.
-
-		@return: A float expressed in seconds since an epoch.
-		"""
-		with monotonic._lock:
-			current = time.time() + monotonic._offset
-			delta = current - monotonic._previous
-			if delta < 0:
-				monotonic._offset -= delta
-				current = monotonic._previous
-			else:
-				monotonic._previous = current
-			return current
-
-	# offset is used to counteract any backward movements
-	monotonic._offset = 0
-	monotonic._previous = time.time()
-	monotonic._lock = threading.Lock()
-- 
2.27.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.