aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <nobody@tensorflow.org>2016-03-17 13:18:45 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-03-18 08:45:52 -0700
commitc51d0a4af7358bffd32e32ccee6d55cd928cf1ce (patch)
treeedb1c05150d235ff193a5189d5f067b154e6e9e6
parentbe86ba738017ffb5ffa407c792cdfa156c7cb4b0 (diff)
Clarifying comment and adding check in should_stop after hitting a confusing snag.
Change: 117484454
-rw-r--r--tensorflow/python/training/coordinator.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tensorflow/python/training/coordinator.py b/tensorflow/python/training/coordinator.py
index 661bae7bc1..f018126bc8 100644
--- a/tensorflow/python/training/coordinator.py
+++ b/tensorflow/python/training/coordinator.py
@@ -131,6 +131,8 @@ class Coordinator(object):
# Event set when threads must stop.
self._stop_event = threading.Event()
# Python exc_info to report.
+ # If not None, it should hold the returned value of sys.exc_info(), which is
+ # a tuple containing exception (type, value, traceback).
self._exc_info_to_raise = None
def request_stop(self, ex=None):
@@ -138,6 +140,10 @@ class Coordinator(object):
After this is called, calls to `should_stop()` will return `True`.
+ Note: If an exception is being passed in, in must be in the context of
+ handling the exception (i.e. `try: ... except Exception as ex: ...`) and not
+ a newly created one.
+
Args:
ex: Optional `Exception`, or Python `exc_info` tuple as returned by
`sys.exc_info()`. If this is the first call to `request_stop()` the
@@ -154,6 +160,22 @@ class Coordinator(object):
logging.info("Error reported to Coordinator: %s",
compat.as_str_any(ex))
self._exc_info_to_raise = sys.exc_info()
+ # self._exc_info_to_raise should contain a tuple containing exception
+ # (type, value, traceback)
+ if (len(self._exc_info_to_raise) != 3 or
+ not self._exc_info_to_raise[0] or
+ not self._exc_info_to_raise[1]):
+ # Raise, catch and record the exception here so that error happens
+ # where expected.
+ try:
+ raise ValueError(
+ "ex must be a tuple or sys.exc_info must return the current "
+ "exception: %s"
+ % self._exc_info_to_raise)
+ except ValueError:
+ # Record this error so it kills the coordinator properly.
+ self._exc_info_to_raise = sys.exc_info()
+
self._stop_event.set()
def clear_stop(self):