Skip to content

Commit

Permalink
asyncio: Enable the debug mode of event loops when the PYTHONASYNCIOD…
Browse files Browse the repository at this point in the history
…EBUG

environment variable is set
  • Loading branch information
vstinner committed Jun 22, 2014
1 parent be1629b commit 576009a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,11 @@ Debug mode

.. 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

Expand Down
3 changes: 2 additions & 1 deletion Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def __init__(self):
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
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_asyncio/test_selector_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,6 @@ def test_connection_lost(self):
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):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def setUp(self):
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()
Expand Down Expand Up @@ -172,7 +172,7 @@ def setUp(self):
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):
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,8 @@ def coro():
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)
Expand Down
8 changes: 0 additions & 8 deletions Lib/test/test_asyncio/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ def test__call_connection_lost(self):
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(
Expand All @@ -462,8 +460,6 @@ def test__call_connection_lost_with_err(self):
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):
Expand Down Expand Up @@ -731,8 +727,6 @@ def test__call_connection_lost(self):
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(
Expand All @@ -747,8 +741,6 @@ def test__call_connection_lost_with_err(self):
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(
Expand Down

0 comments on commit 576009a

Please sign in to comment.