diff --git a/src/calibre/srv/loop.py b/src/calibre/srv/loop.py index c03ba90c89..8f72427116 100644 --- a/src/calibre/srv/loop.py +++ b/src/calibre/srv/loop.py @@ -563,9 +563,9 @@ class ServerLoop(object): pass for s, conn in tuple(self.connection_map.iteritems()): self.close(s, conn) - end = time.time() + self.opts.shutdown_timeout + wait_till = time.time() + self.opts.shutdown_timeout for pool in (self.plugin_pool, self.pool): - pool.stop(max(0, end - time.time())) + pool.stop(wait_till) class EchoLine(Connection): # {{{ diff --git a/src/calibre/srv/pool.py b/src/calibre/srv/pool.py index 955993c9dd..62d339e7e6 100644 --- a/src/calibre/srv/pool.py +++ b/src/calibre/srv/pool.py @@ -60,8 +60,7 @@ class ThreadPool(object): def get_nowait(self): return self.result_queue.get_nowait() - def stop(self, shutdown_timeout): - end = time.time() + shutdown_timeout + def stop(self, wait_till): for w in self.workers: try: self.request_queue.put_nowait(None) @@ -69,9 +68,9 @@ class ThreadPool(object): break for w in self.workers: now = time.time() - if now >= end: + if now >= wait_till: break - w.join(end - now) + w.join(wait_till - now) self.workers = [w for w in self.workers if w.is_alive()] @property @@ -103,13 +102,12 @@ class PluginPool(object): for w in self.workers: w.start() - def stop(self, shutdown_timeout): - end = time.time() + shutdown_timeout + def stop(self, wait_till): for w in self.workers: if w.is_alive(): w.plugin.stop() for w in self.workers: - left = end - time.time() + left = wait_till - time.time() if left > 0: w.join(left) else: