The BForce(BruteForce) library is designed to facilitate complex computation that may require retries or caching for efficient execution. The library consists of decorators that can be easily applied to functions to achieve the desired functionality.
- Python 3.6 or above
To install the library, clone the repository and install it using pip:
pip install bforce
Here are the main features of the library:
The @timeout_retries
decorator allows a function to be retried if it doesn't complete within a specified time limit.
from bforce import timeout_retries
@timeout_retries(timeout=2, max_retries=2)
def my_function(arg1, arg2):
# Your code here
In the example above, if my_function
does not complete within 2 seconds, it will be retried up to 2 times.
The @cacheResult
decorator can be used to cache the result of a function. This is especially useful for time-consuming functions where you want to avoid computing the same result multiple times.
from bforce import cacheResult
@cacheResult("my_cache")
def my_function(arg1, arg2):
# Your code here
In the above example, the result of my_function
will be saved in "my_cache". If the function is called again with the same arguments, the cached result will be returned instead of running the function again.
You can clear the cache using the clear_cache()
function:
from bforce import clear_cache
clear_cache("my_cache")
This will clear all entries in "my_cache".
To run the tests, use the following command:
pytest