MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / wait_until_not_raised

Function wait_until_not_raised

tests/util.py:39–66  ·  view source on GitHub ↗

Executes a function at regular intervals while the condition doesn't raise an exception and the amount of attempts < maxAttempts. :param condition: a function :param delay: the delay in second :param max_attempts: the maximum number of attempts. So the timeout

(condition, delay, max_attempts)

Source from the content-addressed store, hash-verified

37
38
39def wait_until_not_raised(condition, delay, max_attempts):
40 """
41 Executes a function at regular intervals while the condition
42 doesn&#x27;t raise an exception and the amount of attempts < maxAttempts.
43 :param condition: a function
44 :param delay: the delay in second
45 :param max_attempts: the maximum number of attempts. So the timeout
46 of this function will be delay*max_attempts
47 """
48 def wrapped_condition():
49 try:
50 result = condition()
51 except:
52 return False, None
53
54 return True, result
55
56 attempt = 0
57 while attempt < (max_attempts-1):
58 attempt += 1
59 success, result = wrapped_condition()
60 if success:
61 return result
62
63 time.sleep(delay)
64
65 # last attempt, let the exception raise
66 return condition()
67
68
69def late(seconds=1):

Callers 3

setup_moduleFunction · 0.90
submit_requestMethod · 0.90
__test_udtMethod · 0.90

Calls 2

wrapped_conditionFunction · 0.85
sleepMethod · 0.80

Tested by 1

setup_moduleFunction · 0.72