The multiprocessing module now uses the monotonic clock
time.monotonic() instead of the system clock time.time() to implement
timeouts.
(cherry picked from commit
c2368cbc83ca2bafeaea0e4760be4996046d0444)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
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
#
#
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)
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
import threading
import array
import queue
+import time
-from time import time as _time
from traceback import format_exc
from . import connection
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)
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():
import sys
import tempfile
import _multiprocessing
-
-from time import time as _time
+import time
from . import context
from . import process
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)
--- /dev/null
+The multiprocessing module now uses the monotonic clock
+:func:`time.monotonic` instead of the system clock :func:`time.time` to
+implement timeout.