retrying icon indicating copy to clipboard operation
retrying copied to clipboard

@retry decorator seems to have no effect

Open gdhbashton opened this issue 9 years ago • 1 comments

Hullo,

On CentOS 7 (python 2.7.5) I'm trying to validate a trivial script, and the @retry decorator seems to be completely ignored:

import sys
import os
from retrying import retry

@retry
def do_something_unreliable():
    print sys.argv[1]
    if os.system(sys.argv[1]):
        return "fail"
    else:
        return "Awesome sauce!"

print do_something_unreliable()

Transcript showing that there is no competition for the name retry

[root@jenkins ~]# python /usr/local/bin/retry.py false
Traceback (most recent call last):
  File "/usr/local/bin/retry.py", line 3, in <module>
    from retrying import retry
ImportError: No module named retrying
[root@jenkins ~]# pip install retrying
Collecting retrying
  Using cached retrying-1.3.3.tar.gz
Requirement already satisfied (use --upgrade to upgrade): six>=1.7.0 in /usr/lib/python2.7/site-packages (from retrying)
Installing collected packages: retrying
  Running setup.py install for retrying
Successfully installed retrying-1.3.3
[root@jenkins ~]# python /usr/local/bin/retry.py false
false
fail

I was expecting to see false\nfail\n shooting up the screen, but the @retry appears to simply not happen :/ Any advice would be warmly welcomed!

Cheers, Gavin.

gdhbashton avatar Mar 30 '15 13:03 gdhbashton

First, sys.argv[1] is of type str, not Boolean. Therefore, you're if will always be true, and fail will be printed onto the screen.

@retry only retries if an exception is raised. Your function is not raising any exception, therefore it is never retried.

Jiehong avatar Jun 02 '15 16:06 Jiehong