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

Allow Custom Sleep Function #125

Open
stevenjackson121 opened this issue Apr 23, 2021 · 3 comments
Open

Allow Custom Sleep Function #125

stevenjackson121 opened this issue Apr 23, 2021 · 3 comments

Comments

@stevenjackson121
Copy link

stevenjackson121 commented Apr 23, 2021

I think it would be great to add a sleep argument which defaults to asyncio.sleep to improve support for event loops besides asyncio, while keeping it working out of the box for asyncio. I like backoff and would like to stick with it, but it ended up being too much of a hassle to get it working with trio.

tenacity has this feature, with the following syntax/explanation.

You can even use alternative event loops such as curio or Trio by passing the correct sleep function:
    
    @retry(sleep=trio.sleep)
    async def my_async_function(loop):
        await asks.get('https://example.org')
@bgreen-litl
Copy link
Member

Is this just as simple as awaiting a different sleep function here?

https://github.com/litl/backoff/blob/master/backoff/_async.py#L94

if I'm understanding it looks like this would be very easy to accomodate

@stevenjackson121
Copy link
Author

Yes. That should be it! (Of course also adding keyword argument and passing it through as well)

@jmehnle
Copy link

jmehnle commented Jun 13, 2024

No traction on this? :( FYI, tenacity is converging on a solution that not only allows passing in a specific sleep function (it already supports this) but automatically detects whether to use asyncio.sleep or trio.sleep: jd/tenacity#463

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

3 participants