Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to provide arguments to on_backoff function #208

Open
vk496 opened this issue Nov 13, 2023 · 1 comment
Open

How to provide arguments to on_backoff function #208

vk496 opened this issue Nov 13, 2023 · 1 comment

Comments

@vk496
Copy link

vk496 commented Nov 13, 2023

Hello and thank you for this amazing project.

Im experimenting with it and I miss be able to use arguments to the backoff functions. For example:

async def backoff_f(arg1: int):
  pass

@backoff.on_exception(wait_gen=backoff.expo, exception=ValueError, on_backoff=backoff_f(arg1=2), max_tries=5)
@backoff.on_exception(wait_gen=backoff.expo, exception=RuntimeError, on_backoff=backoff_f(arg1=6), max_tries=5)
async def test1() -> int:
  pass

Is that possible?

Thank you in advance

@evgenybf
Copy link

evgenybf commented Feb 22, 2024

It's likely you need "partial" functions

>>> from functools import partial
>>> def a(arg1: int):
...    print(arg1)
...

>>> a_with_2 = partial(a, 2)
>>> a_with_2()
2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants