Skip to content

bpo-34819: Use a monotonic clock to compute timeouts in concurrent.futures #9599

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 3 commits into from
Sep 27, 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/concurrent/futures/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def as_completed(fs, timeout=None):
before the given timeout.
"""
if timeout is not None:
end_time = timeout + time.time()
end_time = timeout + time.monotonic()

fs = set(fs)
total_futures = len(fs)
Expand All @@ -235,7 +235,7 @@ def as_completed(fs, timeout=None):
if timeout is None:
wait_timeout = None
else:
wait_timeout = end_time - time.time()
wait_timeout = end_time - time.monotonic()
if wait_timeout < 0:
raise TimeoutError(
'%d (of %d) futures unfinished' % (
Expand Down Expand Up @@ -578,7 +578,7 @@ def map(self, fn, *iterables, timeout=None, chunksize=1):
Exception: If fn(*args) raises for any values.
"""
if timeout is not None:
end_time = timeout + time.time()
end_time = timeout + time.monotonic()

fs = [self.submit(fn, *args) for args in zip(*iterables)]

Expand All @@ -593,7 +593,7 @@ def result_iterator():
if timeout is None:
yield fs.pop().result()
else:
yield fs.pop().result(end_time - time.time())
yield fs.pop().result(end_time - time.monotonic())
finally:
for future in fs:
future.cancel()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use a monotonic clock to compute timeouts in :meth:`Executor.map` and :func:`as_completed`, in order to prevent timeouts from deviating when the system clock is adjusted.