Skip to content

[3.7] bpo-34054: multiprocessing uses time.monotonic() (GH-8118) #8139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@


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

#
#
Expand Down Expand Up @@ -914,15 +914,15 @@ def wait(object_list, timeout=None):
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)
if ready:
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

Expand Down
6 changes: 3 additions & 3 deletions Lib/multiprocessing/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import threading
import array
import queue
import time

from time import time as _time
from traceback import format_exc

from . import connection
Expand Down Expand Up @@ -1045,13 +1045,13 @@ def wait_for(self, predicate, timeout=None):
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)
Expand Down
4 changes: 2 additions & 2 deletions Lib/multiprocessing/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def get(self, block=True, timeout=None):
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():
Expand Down
7 changes: 3 additions & 4 deletions Lib/multiprocessing/synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import sys
import tempfile
import _multiprocessing

from time import time as _time
import time

from . import context
from . import process
Expand Down Expand Up @@ -302,13 +301,13 @@ def wait_for(self, predicate, timeout=None):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The multiprocessing module now uses the monotonic clock
:func:`time.monotonic` instead of the system clock :func:`time.time` to
implement timeout.