
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Introduction
Redo provides various means to add seamless ability to retry to any Python callable. Redo includes plain functions (redo.retry
, redo.retry_async
), decorators (redo.retriable
, redo.retriable_async
), and a context manager (redo.retrying
) to enable you to integrate it in the best possible way for your project. As a bonus, a standalone interface is also included ("retry"
).
Installation
For installing with pip, run following commands
::
pip install redo
How To Use
Below is the list of functions available
A generator function that sleeps between retries, handles exponential back off and jitter. The action you are retrying is meant to run after retrier yields. At each iteration, we sleep for sleeptime + random.randint(-jitter, jitter)
. Afterwards sleeptime is multiplied by sleepscale for the next iteration.
Arguments Detail:
[-jitter, +jitter]
defaults to 1Output: None, a maximum of attempts
number of times
Example:
::
>>> n = 0
>>> for _ in retrier(sleeptime=0, jitter=0):
... if n == 3:
... # We did the thing!
... break
... n += 1
>>> n
3
>>> n = 0
>>> for _ in retrier(sleeptime=0, jitter=0):
... if n == 6:
... # We did the thing!
... break
... n += 1
... else:
... print("max tries hit")
max tries hit
Calls an action function until it succeeds, or we give up.
Arguments Detail:
[-jitter, +jitter]
defaults to 1action()
, then these are immediately re-raised to the caller.retry_exceptions
is caught. No arguments are passed to the cleanup function; if your cleanup requires arguments, consider using functools.partial
or a lambda
function.action
withaction
withOutput: Whatever action(*args, **kwargs) returns
Output: Whatever action(*args, **kwargs) raises. retry_exceptions
are caught up until the last attempt, in which case they are re-raised.
Example:
::
>>> count = 0
>>> def foo():
... global count
... count += 1
... print(count)
... if count < 3:
... raise ValueError("count is too small!")
... return "success!"
>>> retry(foo, sleeptime=0, jitter=0)
1
2
3
'success!'
An asynchronous function that retries a given async callable.
Arguments Detail:
calculateSleepTime
Exception
func
func
sleeptime_callback
Output: The value from a successful func
call or raises an exception after exceeding attempts.
Example:
::
>>> async def async_action():
... # Your async code here
>>> result = await retry_async(async_action)
A decorator factory for retry()
. Wrap your function in @retriable(...)
to give it retry powers!
Arguments Detail: Same as for retry
, with the exception of action
, args
, and kwargs
, which are left to the normal function definition.
Output: A function decorator
Example:
::
>>> count = 0
>>> @retriable(sleeptime=0, jitter=0)
... def foo():
... global count
... count += 1
... print(count)
... if count < 3:
... raise ValueError("count too small")
... return "success!"
>>> foo()
1
2
3
'success!'
A decorator for asynchronously retrying a function.
Arguments Detail:
Exception
Output: A function decorator that applies retry_async
to the decorated function.
Example:
::
>>> @retriable_async()
... async def async_action():
... # Your async code here
>>> result = await async_action()
A context manager for wrapping functions with retry functionality.
Arguments Detail:
retry
Output: A context manager that returns retriable(func)
on __enter__
Example:
::
>>> count = 0
>>> def foo():
... global count
... count += 1
... print(count)
... if count < 3:
... raise ValueError("count too small")
... return "success!"
>>> with retrying(foo, sleeptime=0, jitter=0) as f:
... f()
1
2
3
'success!'
FAQs
Utilities to retry Python callables.
We found that redo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.