[Python-checkins] cpython: Issue #21645: Add debug code to analyze a failure on FreeBSD 9

victor.stinner python-checkins at python.org
Mon Jul 14 21:31:35 CEST 2014


http://hg.python.org/cpython/rev/a0e6a370755f
changeset:   91679:a0e6a370755f
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jul 14 21:29:23 2014 +0200
summary:
  Issue #21645: Add debug code to analyze a failure on FreeBSD 9

files:
  Lib/test/test_asyncio/test_streams.py |  50 +++++++++-----
  1 files changed, 33 insertions(+), 17 deletions(-)


diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -609,25 +609,41 @@
         rfd, wfd = os.pipe()
         args = [sys.executable, '-c', code, str(wfd)]
 
-        pipe = open(rfd, 'rb', 0)
-        reader = asyncio.StreamReader(loop=self.loop, limit=1)
-        protocol = asyncio.StreamReaderProtocol(reader, loop=self.loop)
-        transport, _ = self.loop.run_until_complete(
-            self.loop.connect_read_pipe(lambda: protocol, pipe))
+        # FIXME: Debug code for issue #21645
+        import logging
+        self.loop.set_debug(True)
+        logger = logging.getLogger('asyncio')
+        log_level = logger.level
+        try:
+            log_handler = logging.StreamHandler(sys.stderr)
+            logger.addHandler(log_handler)
+            logger.setLevel(logging.DEBUG)
+            # FIXME: Debug code for issue #21645 ---
 
-        watcher = asyncio.SafeChildWatcher()
-        watcher.attach_loop(self.loop)
-        try:
-            asyncio.set_child_watcher(watcher)
-            proc = self.loop.run_until_complete(
-                asyncio.create_subprocess_exec(*args, pass_fds={wfd}, loop=self.loop))
-            self.loop.run_until_complete(proc.wait())
+            pipe = open(rfd, 'rb', 0)
+            reader = asyncio.StreamReader(loop=self.loop, limit=1)
+            protocol = asyncio.StreamReaderProtocol(reader, loop=self.loop)
+            transport, _ = self.loop.run_until_complete(
+                self.loop.connect_read_pipe(lambda: protocol, pipe))
+
+            watcher = asyncio.SafeChildWatcher()
+            watcher.attach_loop(self.loop)
+            try:
+                asyncio.set_child_watcher(watcher)
+                proc = self.loop.run_until_complete(
+                    asyncio.create_subprocess_exec(*args, pass_fds={wfd}, loop=self.loop))
+                self.loop.run_until_complete(proc.wait())
+            finally:
+                asyncio.set_child_watcher(None)
+
+            os.close(wfd)
+            data = self.loop.run_until_complete(reader.read(-1))
+            self.assertEqual(data, b'data')
         finally:
-            asyncio.set_child_watcher(None)
-
-        os.close(wfd)
-        data = self.loop.run_until_complete(reader.read(-1))
-        self.assertEqual(data, b'data')
+            # FIXME: Debug code for issue #21645
+            logger.removeHandler(log_handler)
+            logger.setLevel(log_level)
+            # FIXME: Debug code for issue #21645 ---
 
 
 if __name__ == '__main__':

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list