From a7e1f973ccd1abfc0f868f0b9c2382c2034e1633 Mon Sep 17 00:00:00 2001 From: Tony Asleson Date: Wed, 14 Dec 2016 15:30:01 -0600 Subject: [PATCH] lvmdbusd: Use timeout_add instead The function timeout_add_seconds has quite a bit of variability. Using timeout_add which specifies the timeout in ms instead of seconds. Testing shows that this is much more consistent which should improve clients that are using shorter timeouts for the API and the connection. --- daemons/lvmdbusd/request.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/daemons/lvmdbusd/request.py b/daemons/lvmdbusd/request.py index 7c5da461b..78392deba 100644 --- a/daemons/lvmdbusd/request.py +++ b/daemons/lvmdbusd/request.py @@ -19,7 +19,6 @@ from .utils import log_error, mt_async_result class RequestEntry(object): def __init__(self, tmo, method, arguments, cb, cb_error, return_tuple=True, job_state=None): - self.tmo = tmo self.method = method self.arguments = arguments self.cb = cb @@ -35,23 +34,27 @@ class RequestEntry(object): self._return_tuple = return_tuple self._job_state = job_state - if self.tmo < 0: + if tmo < 0: # Client is willing to block forever pass elif tmo == 0: self._return_job() else: - self.timer_id = GLib.timeout_add_seconds( - tmo, RequestEntry._request_timeout, self) + # Note: using 990 instead of 1000 for second to ms conversion to + # account for overhead. Goal is to return just before the + # timeout amount has expired. Better to be a little early than + # late. + self.timer_id = GLib.timeout_add( + tmo * 990, RequestEntry._request_timeout, self) @staticmethod def _request_timeout(r): """ Method which gets called when the timer runs out! :param r: RequestEntry which timed out - :return: Nothing + :return: Result of timer_expired """ - r.timer_expired() + return r.timer_expired() def _return_job(self): # Return job is only called when we create a request object or when