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

retrying #88

Open
itaybz opened this issue Jul 30, 2020 · 3 comments
Open

retrying #88

itaybz opened this issue Jul 30, 2020 · 3 comments

Comments

@itaybz
Copy link

itaybz commented Jul 30, 2020

using the retrying package. How do I use it for retrying, and if the retries ends without a successful match, the code block leaves?

import random
from retrying import retry

@retry(wait_fixed=500, stop_max_delay=5000 )
def do_something_unreliable():
    result = random.randint(0, 10)
    print result
    if result != 11:
        raise IOError("Broken")
    else:
        return True

print do_something_unreliable()

I want the the raise IOError to be replaced with an option of returning, say, False

In other words, I want to use this decorator, in case of actual values is different than expected, while the actual is created frequently from other function

@Harshil783
Copy link

Not Understanding Your Question Please Define More!

@labstersteve
Copy link

Investigate the retry_on_result parameter, which allows you to specify another success criterion.

@itaybz
Copy link
Author

itaybz commented Sep 2, 2020

I want to call a function that always retries to compare one value to another and returns fails after this fails.
Here is the code:

from retrying import retry

@retry( wait_fixed = 500, stop_max_delay = 40000 )
def _do_something_unreliable( actual, expected ):
	print actual, expected
	if actual != expected:  # retry does not succeed
		raise IOError( "Broken" )
	else:
		return True  # retry succeeds


def retry( actual, expect ):
	try:
		x = _do_something_unreliable( actual, expect )

	except:
		x = False

	print x
	return x


result = retry( actual=random.randint(0, 10), expect= 1 )

Any suggestions how to do that?

Obviously it does not work since the compassion is done at the "_do_something_unreliable" function

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