Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d42b492

Browse files
committed
(Merge 3.4) asyncio: Enable the debug mode of event loops when the
PYTHONASYNCIODEBUG environment variable is set
2 parents 33d2e40 + 7b7120e commit d42b492

6 files changed

Lines changed: 11 additions & 14 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,11 @@ Debug mode
585585

586586
.. method:: BaseEventLoop.get_debug()
587587

588-
Get the debug mode (:class:`bool`) of the event loop, ``False`` by default.
588+
Get the debug mode (:class:`bool`) of the event loop.
589+
590+
The default value is ``True`` if the environment variable
591+
:envvar:`PYTHONASYNCIODEBUG` is set to a non-empty string, ``False``
592+
otherwise.
589593

590594
.. versionadded:: 3.4.2
591595

Lib/asyncio/base_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def __init__(self):
137137
self._running = False
138138
self._clock_resolution = time.get_clock_info('monotonic').resolution
139139
self._exception_handler = None
140-
self._debug = False
140+
self._debug = (not sys.flags.ignore_environment
141+
and bool(os.environ.get('PYTHONASYNCIODEBUG')))
141142
# In debug mode, if the execution of a callback or a step of a task
142143
# exceed this duration in seconds, the slow callback/task is logged.
143144
self.slow_callback_duration = 0.1

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,6 @@ def test_connection_lost(self):
682682
self.assertEqual(2, sys.getrefcount(self.protocol),
683683
pprint.pformat(gc.get_referrers(self.protocol)))
684684
self.assertIsNone(tr._loop)
685-
self.assertEqual(3, sys.getrefcount(self.loop),
686-
pprint.pformat(gc.get_referrers(self.loop)))
687685

688686

689687
class SelectorSocketTransportTests(test_utils.TestCase):

Lib/test/test_asyncio/test_subprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def setUp(self):
141141
policy = asyncio.get_event_loop_policy()
142142
self.loop = policy.new_event_loop()
143143

144-
# ensure that the event loop is passed explicitly in the code
144+
# ensure that the event loop is passed explicitly in asyncio
145145
policy.set_event_loop(None)
146146

147147
watcher = self.Watcher()
@@ -172,7 +172,7 @@ def setUp(self):
172172
policy = asyncio.get_event_loop_policy()
173173
self.loop = asyncio.ProactorEventLoop()
174174

175-
# ensure that the event loop is passed explicitly in the code
175+
# ensure that the event loop is passed explicitly in asyncio
176176
policy.set_event_loop(None)
177177

178178
def tearDown(self):

Lib/test/test_asyncio/test_tasks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,8 @@ def coro():
17121712
self.assertIs(fut._loop, self.one_loop)
17131713
gen1.close()
17141714
gen2.close()
1715+
1716+
self.set_event_loop(self.other_loop, cleanup=False)
17151717
gen3 = coro()
17161718
gen4 = coro()
17171719
fut = asyncio.gather(gen3, gen4, loop=self.other_loop)

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,6 @@ def test__call_connection_lost(self):
445445
self.assertEqual(2, sys.getrefcount(self.protocol),
446446
pprint.pformat(gc.get_referrers(self.protocol)))
447447
self.assertIsNone(tr._loop)
448-
self.assertEqual(5, sys.getrefcount(self.loop),
449-
pprint.pformat(gc.get_referrers(self.loop)))
450448

451449
def test__call_connection_lost_with_err(self):
452450
tr = unix_events._UnixReadPipeTransport(
@@ -462,8 +460,6 @@ def test__call_connection_lost_with_err(self):
462460
self.assertEqual(2, sys.getrefcount(self.protocol),
463461
pprint.pformat(gc.get_referrers(self.protocol)))
464462
self.assertIsNone(tr._loop)
465-
self.assertEqual(5, sys.getrefcount(self.loop),
466-
pprint.pformat(gc.get_referrers(self.loop)))
467463

468464

469465
class UnixWritePipeTransportTests(test_utils.TestCase):
@@ -731,8 +727,6 @@ def test__call_connection_lost(self):
731727
self.assertEqual(2, sys.getrefcount(self.protocol),
732728
pprint.pformat(gc.get_referrers(self.protocol)))
733729
self.assertIsNone(tr._loop)
734-
self.assertEqual(5, sys.getrefcount(self.loop),
735-
pprint.pformat(gc.get_referrers(self.loop)))
736730

737731
def test__call_connection_lost_with_err(self):
738732
tr = unix_events._UnixWritePipeTransport(
@@ -747,8 +741,6 @@ def test__call_connection_lost_with_err(self):
747741
self.assertEqual(2, sys.getrefcount(self.protocol),
748742
pprint.pformat(gc.get_referrers(self.protocol)))
749743
self.assertIsNone(tr._loop)
750-
self.assertEqual(5, sys.getrefcount(self.loop),
751-
pprint.pformat(gc.get_referrers(self.loop)))
752744

753745
def test_close(self):
754746
tr = unix_events._UnixWritePipeTransport(

0 commit comments

Comments
 (0)