summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Asleson <tasleson@redhat.com>2016-12-14 15:30:01 -0600
committerTony Asleson <tasleson@redhat.com>2016-12-20 11:06:57 -0600
commita7e1f973ccd1abfc0f868f0b9c2382c2034e1633 (patch)
treee74813e4f258dd82be945746d78ccce1aebec720
parent75568294be01f74ddadbf2c9bacf5d2fce219a44 (diff)
downloadlvm2-a7e1f973ccd1abfc0f868f0b9c2382c2034e1633.tar.gz
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.
-rw-r--r--daemons/lvmdbusd/request.py15
1 files 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