Unverified Kaydet (Commit) 4bd5fce2 authored tarafından Miss Islington (bot)'s avatar Miss Islington (bot) Kaydeden (comit) GitHub

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.
(cherry picked from commit c2368cbc)
Co-authored-by: 's avatarVictor Stinner <vstinner@redhat.com>
üst 4e9d9b31
...@@ -57,10 +57,10 @@ if sys.platform == 'win32': ...@@ -57,10 +57,10 @@ if sys.platform == 'win32':
def _init_timeout(timeout=CONNECTION_TIMEOUT): def _init_timeout(timeout=CONNECTION_TIMEOUT):
return time.time() + timeout return time.monotonic() + timeout
def _check_timeout(t): def _check_timeout(t):
return time.time() > t return time.monotonic() > t
# #
# #
...@@ -914,7 +914,7 @@ else: ...@@ -914,7 +914,7 @@ else:
selector.register(obj, selectors.EVENT_READ) selector.register(obj, selectors.EVENT_READ)
if timeout is not None: if timeout is not None:
deadline = time.time() + timeout deadline = time.monotonic() + timeout
while True: while True:
ready = selector.select(timeout) ready = selector.select(timeout)
...@@ -922,7 +922,7 @@ else: ...@@ -922,7 +922,7 @@ else:
return [key.fileobj for (key, events) in ready] return [key.fileobj for (key, events) in ready]
else: else:
if timeout is not None: if timeout is not None:
timeout = deadline - time.time() timeout = deadline - time.monotonic()
if timeout < 0: if timeout < 0:
return ready return ready
......
...@@ -18,8 +18,8 @@ import sys ...@@ -18,8 +18,8 @@ import sys
import threading import threading
import array import array
import queue import queue
import time
from time import time as _time
from traceback import format_exc from traceback import format_exc
from . import connection from . import connection
...@@ -1045,13 +1045,13 @@ class ConditionProxy(AcquirerProxy): ...@@ -1045,13 +1045,13 @@ class ConditionProxy(AcquirerProxy):
if result: if result:
return result return result
if timeout is not None: if timeout is not None:
endtime = _time() + timeout endtime = time.monotonic() + timeout
else: else:
endtime = None endtime = None
waittime = None waittime = None
while not result: while not result:
if endtime is not None: if endtime is not None:
waittime = endtime - _time() waittime = endtime - time.monotonic()
if waittime <= 0: if waittime <= 0:
break break
self.wait(waittime) self.wait(waittime)
......
...@@ -95,12 +95,12 @@ class Queue(object): ...@@ -95,12 +95,12 @@ class Queue(object):
self._sem.release() self._sem.release()
else: else:
if block: if block:
deadline = time.time() + timeout deadline = time.monotonic() + timeout
if not self._rlock.acquire(block, timeout): if not self._rlock.acquire(block, timeout):
raise Empty raise Empty
try: try:
if block: if block:
timeout = deadline - time.time() timeout = deadline - time.monotonic()
if not self._poll(timeout): if not self._poll(timeout):
raise Empty raise Empty
elif not self._poll(): elif not self._poll():
......
...@@ -15,8 +15,7 @@ import threading ...@@ -15,8 +15,7 @@ import threading
import sys import sys
import tempfile import tempfile
import _multiprocessing import _multiprocessing
import time
from time import time as _time
from . import context from . import context
from . import process from . import process
...@@ -302,13 +301,13 @@ class Condition(object): ...@@ -302,13 +301,13 @@ class Condition(object):
if result: if result:
return result return result
if timeout is not None: if timeout is not None:
endtime = _time() + timeout endtime = time.monotonic() + timeout
else: else:
endtime = None endtime = None
waittime = None waittime = None
while not result: while not result:
if endtime is not None: if endtime is not None:
waittime = endtime - _time() waittime = endtime - time.monotonic()
if waittime <= 0: if waittime <= 0:
break break
self.wait(waittime) self.wait(waittime)
......
The multiprocessing module now uses the monotonic clock
:func:`time.monotonic` instead of the system clock :func:`time.time` to
implement timeout.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment