Retry
flaui.core.tools.Retry
This class contains methods for retrying actions.
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached. |
IsTimeOutReached(start_time, timeout)
staticmethod
Checks if the timeout has been reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
float
|
The start time. |
required |
timeout
|
int
|
The timeout. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the timeout has been reached, False otherwise. |
Source code in flaui/core/tools.py
While(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries the method until the check method returns True.
Example:
Retry.While( retry_method=lambda: main_window.find_first_descendant(condition=cf.by_class_name("#32770")).as_window(), timeout=5, interval=0.1, )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Result of the retry method |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |
Source code in flaui/core/tools.py
WhileEmpty(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries while the result is empty (iterable of length 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Result of the retry method |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |
Source code in flaui/core/tools.py
WhileException(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries while the function raises; returns first successful result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Result of the retry method |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |
Source code in flaui/core/tools.py
WhileFalse(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries while the predicate returns False; succeeds when it becomes True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the predicate became True before timeout, False otherwise |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |
Source code in flaui/core/tools.py
WhileNot(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries the method until the check method returns False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Result of the retry method |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |
Source code in flaui/core/tools.py
WhileNotNull(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries while the result is not None; returns None once it becomes None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Result of the retry method |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |
Source code in flaui/core/tools.py
WhileNull(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries while the result is None; returns first non-None value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
T
|
Result of the retry method |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |
Source code in flaui/core/tools.py
WhileTrue(retry_method, timeout=1000, interval=100, throw_on_timeout=False, ignore_exception=False, timeout_message=None, last_value_on_timeout=False, default_on_timeout=None)
staticmethod
Retries while the predicate returns True; succeeds when it becomes False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
retry_method
|
Callable[[], T]
|
The method to retry. |
required |
timeout
|
int
|
Timeout when the retry aborts, defaults to 1 |
1000
|
interval
|
int
|
Interval of retries, defaults to 0.1 |
100
|
throw_on_timeout
|
bool
|
Flag to indicate if exception is thrown on timeout, defaults to False |
False
|
ignore_exception
|
bool
|
Flag to indicate that exceptions can be ignored, defaults to False |
False
|
timeout_message
|
Optional[str]
|
Message that should be added to the timeout exception incase of a timeout, defaults to None |
None
|
last_value_on_timeout
|
bool
|
Flag to indicate that last value should be returned on timeout, defaults to False |
False
|
default_on_timeout
|
Optional[T]
|
Defines a default value in case of a timeout, defaults to None |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the predicate became False before timeout, False otherwise |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the timeout has been reached |