diff --git a/src/calibre/srv/loop.py b/src/calibre/srv/loop.py index 742b4c7f68..4be6666944 100644 --- a/src/calibre/srv/loop.py +++ b/src/calibre/srv/loop.py @@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2015, Kovid Goyal ' -import ssl, socket, select, os, traceback, time +import ssl, socket, select, os, traceback from io import BytesIO from Queue import Empty, Full from functools import partial @@ -580,7 +580,7 @@ class ServerLoop(object): pass for s, conn in tuple(self.connection_map.iteritems()): self.close(s, conn) - wait_till = time.time() + self.opts.shutdown_timeout + wait_till = monotonic() + self.opts.shutdown_timeout for pool in (self.plugin_pool, self.pool): pool.stop(wait_till) if pool.workers: diff --git a/src/calibre/srv/pool.py b/src/calibre/srv/pool.py index 3a3eae86f9..bb2e2e626a 100644 --- a/src/calibre/srv/pool.py +++ b/src/calibre/srv/pool.py @@ -6,10 +6,12 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2015, Kovid Goyal ' -import sys, time +import sys from Queue import Queue, Full from threading import Thread +from calibre.utils.monotonic import monotonic + class Worker(Thread): daemon = True @@ -67,7 +69,7 @@ class ThreadPool(object): except Full: break for w in self.workers: - now = time.time() + now = monotonic() if now >= wait_till: break w.join(wait_till - now) @@ -113,7 +115,7 @@ class PluginPool(object): except Exception: self.loop.log.exception('Failed to stop plugin: %s', self.plugin_name(w.plugin)) for w in self.workers: - left = wait_till - time.time() + left = wait_till - monotonic() if left > 0: w.join(left) else: