You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by an...@apache.org on 2018/06/15 23:58:18 UTC

[incubator-mxnet] branch v1.2.0 updated: Fix discard_stderr (#11309)

This is an automated email from the ASF dual-hosted git repository.

anirudh2290 pushed a commit to branch v1.2.0
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/v1.2.0 by this push:
     new daa957c  Fix discard_stderr (#11309)
daa957c is described below

commit daa957c9c811b1abd09b98e8fb5ff2c06cad9ad8
Author: Marco de Abreu <ma...@users.noreply.github.com>
AuthorDate: Fri Jun 15 16:57:43 2018 -0700

    Fix discard_stderr (#11309)
---
 python/mxnet/test_utils.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/python/mxnet/test_utils.py b/python/mxnet/test_utils.py
index aa388c1..7a9c9b5 100644
--- a/python/mxnet/test_utils.py
+++ b/python/mxnet/test_utils.py
@@ -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

-- 
To stop receiving notification emails like this one, please contact
anirudh2290@apache.org.