[Python-checkins] cpython (3.4): asyncio: Enable the debug mode of event loops when the PYTHONASYNCIODEBUG

victor.stinner python-checkins at python.org
Mon Jun 23 00:15:38 CEST 2014


http://hg.python.org/cpython/rev/2228222faa7e
changeset:   91325:2228222faa7e
branch:      3.4
parent:      91323:4cd3e1f9c250
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jun 23 00:12:14 2014 +0200
summary:
  asyncio: Enable the debug mode of event loops when the PYTHONASYNCIODEBUG
environment variable is set

files:
  Doc/library/asyncio-eventloop.rst             |  6 +++++-
  Lib/asyncio/base_events.py                    |  3 ++-
  Lib/test/test_asyncio/test_selector_events.py |  2 --
  Lib/test/test_asyncio/test_subprocess.py      |  4 ++--
  Lib/test/test_asyncio/test_tasks.py           |  2 ++
  Lib/test/test_asyncio/test_unix_events.py     |  8 --------
  6 files changed, 11 insertions(+), 14 deletions(-)


diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst
--- a/Doc/library/asyncio-eventloop.rst
+++ b/Doc/library/asyncio-eventloop.rst
@@ -585,7 +585,11 @@
 
 .. method:: BaseEventLoop.get_debug()
 
-   Get the debug mode (:class:`bool`) of the event loop, ``False`` by default.
+   Get the debug mode (:class:`bool`) of the event loop.
+
+   The default value is ``True`` if the environment variable
+   :envvar:`PYTHONASYNCIODEBUG` is set to a non-empty string, ``False``
+   otherwise.
 
    .. versionadded:: 3.4.2
 
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -137,7 +137,8 @@
         self._running = False
         self._clock_resolution = time.get_clock_info('monotonic').resolution
         self._exception_handler = None
-        self._debug = False
+        self._debug = (not sys.flags.ignore_environment
+                       and bool(os.environ.get('PYTHONASYNCIODEBUG')))
         # In debug mode, if the execution of a callback or a step of a task
         # exceed this duration in seconds, the slow callback/task is logged.
         self.slow_callback_duration = 0.1
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -682,8 +682,6 @@
         self.assertEqual(2, sys.getrefcount(self.protocol),
                          pprint.pformat(gc.get_referrers(self.protocol)))
         self.assertIsNone(tr._loop)
-        self.assertEqual(3, sys.getrefcount(self.loop),
-                         pprint.pformat(gc.get_referrers(self.loop)))
 
 
 class SelectorSocketTransportTests(test_utils.TestCase):
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -141,7 +141,7 @@
             policy = asyncio.get_event_loop_policy()
             self.loop = policy.new_event_loop()
 
-            # ensure that the event loop is passed explicitly in the code
+            # ensure that the event loop is passed explicitly in asyncio
             policy.set_event_loop(None)
 
             watcher = self.Watcher()
@@ -172,7 +172,7 @@
             policy = asyncio.get_event_loop_policy()
             self.loop = asyncio.ProactorEventLoop()
 
-            # ensure that the event loop is passed explicitly in the code
+            # ensure that the event loop is passed explicitly in asyncio
             policy.set_event_loop(None)
 
         def tearDown(self):
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1712,6 +1712,8 @@
         self.assertIs(fut._loop, self.one_loop)
         gen1.close()
         gen2.close()
+
+        self.set_event_loop(self.other_loop, cleanup=False)
         gen3 = coro()
         gen4 = coro()
         fut = asyncio.gather(gen3, gen4, loop=self.other_loop)
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -445,8 +445,6 @@
         self.assertEqual(2, sys.getrefcount(self.protocol),
                          pprint.pformat(gc.get_referrers(self.protocol)))
         self.assertIsNone(tr._loop)
-        self.assertEqual(5, sys.getrefcount(self.loop),
-                         pprint.pformat(gc.get_referrers(self.loop)))
 
     def test__call_connection_lost_with_err(self):
         tr = unix_events._UnixReadPipeTransport(
@@ -462,8 +460,6 @@
         self.assertEqual(2, sys.getrefcount(self.protocol),
                          pprint.pformat(gc.get_referrers(self.protocol)))
         self.assertIsNone(tr._loop)
-        self.assertEqual(5, sys.getrefcount(self.loop),
-                         pprint.pformat(gc.get_referrers(self.loop)))
 
 
 class UnixWritePipeTransportTests(test_utils.TestCase):
@@ -731,8 +727,6 @@
         self.assertEqual(2, sys.getrefcount(self.protocol),
                          pprint.pformat(gc.get_referrers(self.protocol)))
         self.assertIsNone(tr._loop)
-        self.assertEqual(5, sys.getrefcount(self.loop),
-                         pprint.pformat(gc.get_referrers(self.loop)))
 
     def test__call_connection_lost_with_err(self):
         tr = unix_events._UnixWritePipeTransport(
@@ -747,8 +741,6 @@
         self.assertEqual(2, sys.getrefcount(self.protocol),
                          pprint.pformat(gc.get_referrers(self.protocol)))
         self.assertIsNone(tr._loop)
-        self.assertEqual(5, sys.getrefcount(self.loop),
-                         pprint.pformat(gc.get_referrers(self.loop)))
 
     def test_close(self):
         tr = unix_events._UnixWritePipeTransport(

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


More information about the Python-checkins mailing list