Skip to content

Commit ccd6fde

Browse files
authored
Silence deprecation warning spam about tf_record_iterator (#3319)
1 parent 5717630 commit ccd6fde

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tensorboard/backend/event_processing/event_file_loader.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from __future__ import division
1919
from __future__ import print_function
2020

21+
import contextlib
22+
2123
from tensorboard.compat import tf
2224
from tensorboard.compat.proto import event_pb2
2325
from tensorboard.util import platform_util
@@ -27,6 +29,27 @@
2729
logger = tb_logging.get_logger()
2830

2931

32+
@contextlib.contextmanager
33+
def _nullcontext():
34+
"""Pre-Python-3.7-compatible standin for contextlib.nullcontext."""
35+
yield
36+
37+
38+
# Might as well make this a singleton.
39+
_NULLCONTEXT = _nullcontext()
40+
41+
42+
def _silence_deprecation_warnings():
43+
"""Context manager that best-effort silences TF deprecation warnings."""
44+
try:
45+
# Learn this one weird trick to make TF deprecation warnings go away.
46+
from tensorflow.python.util import deprecation
47+
48+
return deprecation.silence()
49+
except (ImportError, AttributeError):
50+
return _NULLCONTEXT
51+
52+
3053
def _make_tf_record_iterator(file_path):
3154
"""Returns an iterator over TF records for the given tfrecord file."""
3255
# If we don't have TF at all, use the stub implementation.
@@ -55,7 +78,9 @@ def _make_tf_record_iterator(file_path):
5578
return _PyRecordReaderIterator(py_record_reader_new, file_path)
5679
else:
5780
logger.debug("Opening a tf_record_iterator pointing at %s", file_path)
58-
return tf.compat.v1.io.tf_record_iterator(file_path)
81+
# TODO(#1711): Find non-deprecated replacement for tf_record_iterator.
82+
with _silence_deprecation_warnings():
83+
return tf.compat.v1.io.tf_record_iterator(file_path)
5984

6085

6186
class _PyRecordReaderIterator(object):

0 commit comments

Comments
 (0)