1 |
time.monotonic() is available since py3.3, so there's no need for |
2 |
the compat anymore. |
3 |
|
4 |
Signed-off-by: Michał Górny <mgorny@g.o> |
5 |
--- |
6 |
lib/portage/dbapi/vartree.py | 7 ++-- |
7 |
lib/portage/tests/util/futures/test_retry.py | 8 ++--- |
8 |
lib/portage/util/_eventloop/EventLoop.py | 6 ++-- |
9 |
lib/portage/util/monotonic.py | 34 -------------------- |
10 |
4 files changed, 10 insertions(+), 45 deletions(-) |
11 |
delete mode 100644 lib/portage/util/monotonic.py |
12 |
|
13 |
diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py |
14 |
index 3687b471b..80ca0ab80 100644 |
15 |
--- a/lib/portage/dbapi/vartree.py |
16 |
+++ b/lib/portage/dbapi/vartree.py |
17 |
@@ -1,4 +1,4 @@ |
18 |
-# Copyright 1998-2019 Gentoo Authors |
19 |
+# Copyright 1998-2020 Gentoo Authors |
20 |
# Distributed under the terms of the GNU General Public License v2 |
21 |
|
22 |
from __future__ import division, unicode_literals |
23 |
@@ -36,7 +36,6 @@ portage.proxy.lazyimport.lazyimport(globals(), |
24 |
'portage.util.install_mask:install_mask_dir,InstallMask,_raise_exc', |
25 |
'portage.util.listdir:dircache,listdir', |
26 |
'portage.util.movefile:movefile', |
27 |
- 'portage.util.monotonic:monotonic', |
28 |
'portage.util.path:first_existing,iter_parents', |
29 |
'portage.util.writeable_check:get_ro_checker', |
30 |
'portage.util._xattr:xattr', |
31 |
@@ -3616,7 +3615,7 @@ class dblink(object): |
32 |
symlink_collisions = [] |
33 |
destroot = self.settings['ROOT'] |
34 |
totfiles = len(file_list) + len(symlink_list) |
35 |
- previous = monotonic() |
36 |
+ previous = time.monotonic() |
37 |
progress_shown = False |
38 |
report_interval = 1.7 # seconds |
39 |
falign = len("%d" % totfiles) |
40 |
@@ -3625,7 +3624,7 @@ class dblink(object): |
41 |
for i, (f, f_type) in enumerate(chain( |
42 |
((f, "reg") for f in file_list), |
43 |
((f, "sym") for f in symlink_list))): |
44 |
- current = monotonic() |
45 |
+ current = time.monotonic() |
46 |
if current - previous > report_interval: |
47 |
showMessage(_("%3d%% done, %*d files remaining ...\n") % |
48 |
(i * 100 / totfiles, falign, totfiles - i)) |
49 |
diff --git a/lib/portage/tests/util/futures/test_retry.py b/lib/portage/tests/util/futures/test_retry.py |
50 |
index 7a1e76280..4530bba83 100644 |
51 |
--- a/lib/portage/tests/util/futures/test_retry.py |
52 |
+++ b/lib/portage/tests/util/futures/test_retry.py |
53 |
@@ -1,4 +1,4 @@ |
54 |
-# Copyright 2018 Gentoo Foundation |
55 |
+# Copyright 2018-2020 Gentoo Authors |
56 |
# Distributed under the terms of the GNU General Public License v2 |
57 |
|
58 |
try: |
59 |
@@ -12,6 +12,7 @@ except ImportError: |
60 |
import dummy_threading as threading |
61 |
|
62 |
import sys |
63 |
+import time |
64 |
|
65 |
from portage.tests import TestCase |
66 |
from portage.util._eventloop.global_event_loop import global_event_loop |
67 |
@@ -19,7 +20,6 @@ from portage.util.backoff import RandomExponentialBackoff |
68 |
from portage.util.futures import asyncio |
69 |
from portage.util.futures.retry import retry |
70 |
from portage.util.futures.executor.fork import ForkExecutor |
71 |
-from portage.util.monotonic import monotonic |
72 |
|
73 |
|
74 |
class SucceedLaterException(Exception): |
75 |
@@ -31,12 +31,12 @@ class SucceedLater(object): |
76 |
A callable object that succeeds some duration of time has passed. |
77 |
""" |
78 |
def __init__(self, duration): |
79 |
- self._succeed_time = monotonic() + duration |
80 |
+ self._succeed_time = time.monotonic() + duration |
81 |
|
82 |
def __call__(self): |
83 |
loop = global_event_loop() |
84 |
result = loop.create_future() |
85 |
- remaining = self._succeed_time - monotonic() |
86 |
+ remaining = self._succeed_time - time.monotonic() |
87 |
if remaining > 0: |
88 |
loop.call_soon_threadsafe(lambda: None if result.done() else |
89 |
result.set_exception(SucceedLaterException( |
90 |
diff --git a/lib/portage/util/_eventloop/EventLoop.py b/lib/portage/util/_eventloop/EventLoop.py |
91 |
index ffd12cff9..a3bea97aa 100644 |
92 |
--- a/lib/portage/util/_eventloop/EventLoop.py |
93 |
+++ b/lib/portage/util/_eventloop/EventLoop.py |
94 |
@@ -1,4 +1,4 @@ |
95 |
-# Copyright 1999-2018 Gentoo Foundation |
96 |
+# Copyright 1999-2020 Gentoo Authors |
97 |
# Distributed under the terms of the GNU General Public License v2 |
98 |
|
99 |
from __future__ import division |
100 |
@@ -11,6 +11,7 @@ import os |
101 |
import select |
102 |
import signal |
103 |
import sys |
104 |
+import time |
105 |
import traceback |
106 |
|
107 |
try: |
108 |
@@ -37,7 +38,6 @@ portage.proxy.lazyimport.lazyimport(globals(), |
109 |
) |
110 |
|
111 |
from portage.util import writemsg_level |
112 |
-from portage.util.monotonic import monotonic |
113 |
from ..SlotObject import SlotObject |
114 |
from .PollConstants import PollConstants |
115 |
from .PollSelectAdapter import PollSelectAdapter |
116 |
@@ -887,7 +887,7 @@ class EventLoop(object): |
117 |
epoch, precision, accuracy and drift are unspecified and may |
118 |
differ per event loop. |
119 |
""" |
120 |
- return monotonic() |
121 |
+ return time.monotonic() |
122 |
|
123 |
def call_later(self, delay, callback, *args, **kwargs): |
124 |
""" |
125 |
diff --git a/lib/portage/util/monotonic.py b/lib/portage/util/monotonic.py |
126 |
deleted file mode 100644 |
127 |
index e50564851..000000000 |
128 |
--- a/lib/portage/util/monotonic.py |
129 |
+++ /dev/null |
130 |
@@ -1,34 +0,0 @@ |
131 |
-# Copyright 2018 Gentoo Foundation |
132 |
-# Distributed under the terms of the GNU General Public License v2 |
133 |
- |
134 |
-__all__ = ['monotonic'] |
135 |
- |
136 |
-import time |
137 |
-try: |
138 |
- import threading |
139 |
-except ImportError: |
140 |
- import dummy_threading as threading |
141 |
- |
142 |
-monotonic = getattr(time, 'monotonic', None) |
143 |
- |
144 |
-if monotonic is None: |
145 |
- def monotonic(): |
146 |
- """ |
147 |
- Emulate time.monotonic() which is available in Python 3.3 and later. |
148 |
- |
149 |
- @return: A float expressed in seconds since an epoch. |
150 |
- """ |
151 |
- with monotonic._lock: |
152 |
- current = time.time() + monotonic._offset |
153 |
- delta = current - monotonic._previous |
154 |
- if delta < 0: |
155 |
- monotonic._offset -= delta |
156 |
- current = monotonic._previous |
157 |
- else: |
158 |
- monotonic._previous = current |
159 |
- return current |
160 |
- |
161 |
- # offset is used to counteract any backward movements |
162 |
- monotonic._offset = 0 |
163 |
- monotonic._previous = time.time() |
164 |
- monotonic._lock = threading.Lock() |
165 |
-- |
166 |
2.27.0 |