Skip to content
Permalink
Browse files

Move the elapsed computation and print from _wait() to wait()

  • Loading branch information...
cvaroqui committed Jul 23, 2019
1 parent 201090a commit 1cc1aee32264d6a85b567d399f3798d88d76c557
Showing with 5 additions and 16 deletions.
  1. +5 −16 lib/node.py
@@ -3343,16 +3343,19 @@ def wait(self):
server = self.options.server
duration = self.options.duration
verbose = self.options.verbose
begin = time.time()
try:
self._wait(server, path, duration, verbose)
self._wait(server, path, duration)
if self.options.verbose:
print("elapsed %.2f seconds"% (time.time() - begin))
except KeyboardInterrupt:
return 1
except (OSError, IOError) as exc:
if exc.errno == 32:
# broken pipe
return 1

def _wait(self, server=None, path=None, duration=None, verbose=None):
def _wait(self, server=None, path=None, duration=None):
"""
Wait for a condition on the monitor thread data or
a local event data.
@@ -3362,9 +3365,6 @@ def _wait(self, server=None, path=None, duration=None, verbose=None):
if not path:
return

if verbose:
begin = time.time()

if server is None:
server = rcEnv.nodename

@@ -3398,10 +3398,6 @@ def _wait(self, server=None, path=None, duration=None, verbose=None):
except Exception as exc:
raise ex.excError(exc)

def elapsed(self, begin):
elapsed = time.time() - begin
print("elapsed %.2f seconds"%elapsed)

def eval_cond(val, data):
for match in jsonpath_expr.find(data):
if oper is None:
@@ -3457,15 +3453,11 @@ def match_event(msg):
raise ex.excError("could not fetch cluster data")

if neg ^ eval_cond(val, cluster_data):
if verbose:
elapsed(self, begin)
return

if duration:
import signal
def alarm_handler(signum, frame):
if verbose:
elapsed(self, begin)
print("timeout", file=sys.stderr)
raise KeyboardInterrupt
signal.signal(signal.SIGALRM, alarm_handler)
@@ -3495,9 +3487,6 @@ def alarm_handler(signum, frame):
if match_event(patch):
break

if verbose:
elapsed(self, begin)

def events(self, server=None):
try:
self._events(server=server)

0 comments on commit 1cc1aee

Please sign in to comment.
You can’t perform that action at this time.