Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/verify/wait.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """Abstraction for waiting on API conditions to become true.""" | |
2 | |
3 import time | |
4 | |
5 DEFAULT_POLLING_BACKOFF = 0 | |
6 DEFAULT_POLLING_DELTA = 0.25 | |
7 | |
8 TIMEOUT_MESSAGE_TEMPLATE = "Timed out after {} seconds waiting on {}." | |
9 | |
10 | |
11 def wait_on(function, desc, timeout, delta=DEFAULT_POLLING_DELTA, polling_backoff=DEFAULT_POLLING_BACKOFF, sleep_=None): | |
12 """Wait for function to return non-None value. | |
13 | |
14 Grow the polling interval (initially ``delta`` defaulting to 0.25 seconds) | |
15 incrementally by the supplied ``polling_backoff`` (defaulting to 0). | |
16 | |
17 Throw a TimeoutAssertionError if the supplied timeout is reached without | |
18 supplied function ever returning a non-None value. | |
19 """ | |
20 sleep = sleep_ or time.sleep | |
21 total_wait = 0 | |
22 while True: | |
23 if total_wait > timeout: | |
24 raise TimeoutAssertionError(TIMEOUT_MESSAGE_TEMPLATE.format(total_wait, desc)) | |
25 value = function() | |
26 if value is not None: | |
27 return value | |
28 total_wait += delta | |
29 sleep(delta) | |
30 delta += polling_backoff | |
31 | |
32 | |
33 class TimeoutAssertionError(AssertionError): | |
34 """Derivative of AssertionError indicating wait_on exceeded max time.""" | |
35 | |
36 def __init__(self, message): | |
37 super().__init__(message) |