From b312adf29fab8c7078186dd086ca15dca50c9fd2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 3 Jun 2015 18:30:09 +0530 Subject: [PATCH] ... --- src/calibre/srv/loop.py | 4 ++-- src/calibre/srv/pool.py | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) 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: