diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-07-06 13:51:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-06 13:51:52 +0200 |
commit | c2368cbc83ca2bafeaea0e4760be4996046d0444 (patch) | |
tree | e68abf5dc1a0a3299fda6763410cb41a300cda74 /Lib | |
parent | fix two typos in Objects/odictobject.c comments (GH-8040) (diff) | |
download | cpython-c2368cbc83ca2bafeaea0e4760be4996046d0444.tar.gz cpython-c2368cbc83ca2bafeaea0e4760be4996046d0444.tar.bz2 cpython-c2368cbc83ca2bafeaea0e4760be4996046d0444.zip |
bpo-34054: multiprocessing uses time.monotonic() (GH-8118)
The multiprocessing module now uses the monotonic clock
time.monotonic() instead of the system clock time.time() to implement
timeouts.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/multiprocessing/connection.py | 8 | ||||
-rw-r--r-- | Lib/multiprocessing/managers.py | 6 | ||||
-rw-r--r-- | Lib/multiprocessing/queues.py | 4 | ||||
-rw-r--r-- | Lib/multiprocessing/synchronize.py | 7 |
4 files changed, 12 insertions, 13 deletions
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index 7a621a55f46..1f3ea504fff 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -57,10 +57,10 @@ if sys.platform == 'win32': def _init_timeout(timeout=CONNECTION_TIMEOUT): - return time.time() + timeout + return time.monotonic() + timeout def _check_timeout(t): - return time.time() > t + return time.monotonic() > t # # @@ -914,7 +914,7 @@ else: selector.register(obj, selectors.EVENT_READ) if timeout is not None: - deadline = time.time() + timeout + deadline = time.monotonic() + timeout while True: ready = selector.select(timeout) @@ -922,7 +922,7 @@ else: return [key.fileobj for (key, events) in ready] else: if timeout is not None: - timeout = deadline - time.time() + timeout = deadline - time.monotonic() if timeout < 0: return ready diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py index 04df26bac66..3f263802bc7 100644 --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -18,8 +18,8 @@ import sys import threading import array import queue +import time -from time import time as _time from traceback import format_exc from . import connection @@ -1045,13 +1045,13 @@ class ConditionProxy(AcquirerProxy): if result: return result if timeout is not None: - endtime = _time() + timeout + endtime = time.monotonic() + timeout else: endtime = None waittime = None while not result: if endtime is not None: - waittime = endtime - _time() + waittime = endtime - time.monotonic() if waittime <= 0: break self.wait(waittime) diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py index 715a9b0e129..88f7d267bfd 100644 --- a/Lib/multiprocessing/queues.py +++ b/Lib/multiprocessing/queues.py @@ -95,12 +95,12 @@ class Queue(object): self._sem.release() else: if block: - deadline = time.time() + timeout + deadline = time.monotonic() + timeout if not self._rlock.acquire(block, timeout): raise Empty try: if block: - timeout = deadline - time.time() + timeout = deadline - time.monotonic() if not self._poll(timeout): raise Empty elif not self._poll(): diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py index 038f73f6b76..5137c49c1b6 100644 --- a/Lib/multiprocessing/synchronize.py +++ b/Lib/multiprocessing/synchronize.py @@ -15,8 +15,7 @@ import threading import sys import tempfile import _multiprocessing - -from time import time as _time +import time from . import context from . import process @@ -302,13 +301,13 @@ class Condition(object): if result: return result if timeout is not None: - endtime = _time() + timeout + endtime = time.monotonic() + timeout else: endtime = None waittime = None while not result: if endtime is not None: - waittime = endtime - _time() + waittime = endtime - time.monotonic() if waittime <= 0: break self.wait(waittime) |