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

Retry decorator not invoked if function it wraps is a generator function #23

Open
purplehat7 opened this issue Nov 21, 2018 · 1 comment

Comments

@purplehat7
Copy link

Consider:

from retry import retry

import logging

logger = logging.getLogger()

@retry((Exception,), tries=2, logger=logger)
def raise_error_generator():
    raise Exception('error')
    ret = []
    for i in range(5):
        ret.append(i)
    return ret

def my_func():
    for i in raise_error_generator():
        print(i)

my_func()

...which gives:

error, retrying in 0 seconds...
Traceback (most recent call last):
  File "test_retry_decorator.py", line 19, in <module>
    my_func()
  File "test_retry_decorator.py", line 16, in my_func
    for i in raise_error_generator():
  File "<decorator-gen-2>", line 2, in raise_error_generator
  File "/Users/alcanno/.virtualenvs/facebook3/lib/python3.7/site-packages/retry/api.py", line 74, in retry_decorator
    logger)
  File "/Users/alcanno/.virtualenvs/facebook3/lib/python3.7/site-packages/retry/api.py", line 33, in __retry_internal
    return f()
  File "test_retry_decorator.py", line 9, in raise_error_generator
    raise Exception('error')
Exception: error

vs:

from retry import retry

import logging

logger = logging.getLogger()

@retry((Exception,), tries=2, logger=logger)
def raise_error_generator():
    raise Exception('error')
    for i in range(5):
        yield i

def my_func():
    for i in raise_error_generator():
        print(i)

my_func()

...which gives (note the lack of the log message from the retry decorator, indicating the function was not retried).

Traceback (most recent call last):
  File "test_retry_decorator.py", line 17, in <module>
    my_func()
  File "test_retry_decorator.py", line 14, in my_func
    for i in raise_error_generator():
  File "test_retry_decorator.py", line 9, in raise_error_generator
    raise Exception('error')
Exception: error
@purplehat7
Copy link
Author

This seems to be related to #11

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

1 participant