Use monotonic() instead of wall clock time for shutdown timeout

This commit is contained in:
Kovid Goyal 2015-06-17 11:51:29 +05:30
parent 304d1a6f90
commit f4d5841f74
2 changed files with 7 additions and 5 deletions

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
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:

View File

@ -6,10 +6,12 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
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: