aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/learn
diff options
context:
space:
mode:
authorGravatar James Keeling <jtkeeling@google.com>2018-03-27 09:36:52 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-03-27 09:39:08 -0700
commitfdec18588d7f8b5f6383601f1030ed71f634d1c0 (patch)
tree71e28e2e3c4d3fea7640410bb68690932819afda /tensorflow/contrib/learn
parentff9040f645a042ef62782be0eed8b4597e80ce6c (diff)
Prevent warning every time someone imports contrib.learn.datasets.base
Everything in contrib/learn/python/learn/datasets/base.py has been deprecated. One of the function in there is a decorator, retry. Because another function in that file is decorated with retry, the function is called upon import, which prints a warning. I have fixed this by adding a private function, _internal_retry, which is used internally, and redefining retry to simply call this. That way, using retry in user-code will still print the deprecated warning, but it's not printed upon every import. I also cleaned up the docstrings slightly. PiperOrigin-RevId: 190626717
Diffstat (limited to 'tensorflow/contrib/learn')
-rw-r--r--tensorflow/contrib/learn/python/learn/datasets/base.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/tensorflow/contrib/learn/python/learn/datasets/base.py b/tensorflow/contrib/learn/python/learn/datasets/base.py
index 3b5c9b97c0..4676eedb20 100644
--- a/tensorflow/contrib/learn/python/learn/datasets/base.py
+++ b/tensorflow/contrib/learn/python/learn/datasets/base.py
@@ -139,15 +139,48 @@ def retry(initial_delay,
Args:
initial_delay: the initial delay.
+ max_delay: the maximum delay allowed (actual max is
+ max_delay * (1 + jitter).
factor: each subsequent retry, the delay is multiplied by this value.
(must be >= 1).
jitter: to avoid lockstep, the returned delay is multiplied by a random
number between (1-jitter) and (1+jitter). To add a 20% jitter, set
jitter = 0.2. Must be < 1.
+ is_retriable: (optional) a function that takes an Exception as an argument
+ and returns true if retry should be applied.
+
+ Returns:
+ A function that wraps another function to automatically retry it.
+ """
+ return _internal_retry(
+ initial_delay=initial_delay,
+ max_delay=max_delay,
+ factor=factor,
+ jitter=jitter,
+ is_retriable=is_retriable)
+
+
+def _internal_retry(initial_delay,
+ max_delay,
+ factor=2.0,
+ jitter=0.25,
+ is_retriable=None):
+ """Simple decorator for wrapping retriable functions, for internal use only.
+
+ Args:
+ initial_delay: the initial delay.
max_delay: the maximum delay allowed (actual max is
max_delay * (1 + jitter).
+ factor: each subsequent retry, the delay is multiplied by this value.
+ (must be >= 1).
+ jitter: to avoid lockstep, the returned delay is multiplied by a random
+ number between (1-jitter) and (1+jitter). To add a 20% jitter, set
+ jitter = 0.2. Must be < 1.
is_retriable: (optional) a function that takes an Exception as an argument
and returns true if retry should be applied.
+
+ Returns:
+ A function that wraps another function to automatically retry it.
"""
if factor < 1:
raise ValueError('factor must be >= 1; was %f' % (factor,))
@@ -195,7 +228,7 @@ def _is_retriable(e):
@deprecated(None, 'Please use urllib or similar directly.')
-@retry(initial_delay=1.0, max_delay=16.0, is_retriable=_is_retriable)
+@_internal_retry(initial_delay=1.0, max_delay=16.0, is_retriable=_is_retriable)
def urlretrieve_with_retry(url, filename=None):
return urllib.request.urlretrieve(url, filename)