Skip to content

Commit

Permalink
Fix discard_stderr (apache#11309)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoabreu authored and anirudh2290 committed Jun 15, 2018
1 parent 332056a commit daa957c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions python/mxnet/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,20 +1623,22 @@ def same_array(array1, array2):
def discard_stderr():
"""
Discards error output of a routine if invoked as:
with discard_stderr():
...
"""

try:
stderr_fileno = sys.stderr.fileno()
old_stderr = os.dup(stderr_fileno)
bit_bucket = open(os.devnull, 'w')
os.dup2(bit_bucket.fileno(), stderr_fileno)
yield
finally:
os.dup2(old_stderr, stderr_fileno)
bit_bucket.close()
with open(os.devnull, 'w') as bit_bucket:
try:
stderr_fileno = sys.stderr.fileno()
old_stderr = os.dup(stderr_fileno)
try:
os.dup2(bit_bucket.fileno(), stderr_fileno)
yield
finally:
os.dup2(old_stderr, stderr_fileno)
except AttributeError:
# On some systems is stderr not a file descriptor but actually a virtual pipeline
# that can not be copied
yield

class DummyIter(mx.io.DataIter):
"""A dummy iterator that always returns the same batch of data
Expand Down

0 comments on commit daa957c

Please sign in to comment.