diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-02-19 22:15:02 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-02-19 22:15:02 (GMT) |
commit | 7ef60cd8c208d22672e76fcf031b4fa671a13684 (patch) | |
tree | 450d12c31c3fe734566c85bcc0d04c4301a37836 /Lib/asyncio | |
parent | f4558e8b54da0a7caf800c80589d934186b16f79 (diff) | |
download | cpython-7ef60cd8c208d22672e76fcf031b4fa671a13684.zip cpython-7ef60cd8c208d22672e76fcf031b4fa671a13684.tar.gz cpython-7ef60cd8c208d22672e76fcf031b4fa671a13684.tar.bz2 |
asyncio, Tulip issue #136: Add get/set_debug() methods to BaseEventLoopTests.
Add also a PYTHONASYNCIODEBUG environment variable to debug coroutines since
Python startup, to be able to debug coroutines defined directly in the asyncio
module.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/base_events.py | 7 | ||||
-rw-r--r-- | Lib/asyncio/events.py | 8 | ||||
-rw-r--r-- | Lib/asyncio/tasks.py | 5 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index b94ba07..69caa4d 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -123,6 +123,7 @@ class BaseEventLoop(events.AbstractEventLoop): self._running = False self._clock_resolution = time.get_clock_info('monotonic').resolution self._exception_handler = None + self._debug = False def _make_socket_transport(self, sock, protocol, waiter=None, *, extra=None, server=None): @@ -795,3 +796,9 @@ class BaseEventLoop(events.AbstractEventLoop): if not handle._cancelled: handle._run() handle = None # Needed to break cycles when an exception occurs. + + def get_debug(self): + return self._debug + + def set_debug(self, enabled): + self._debug = enabled diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index 1030c04..5362f05 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -345,6 +345,14 @@ class AbstractEventLoop: def call_exception_handler(self, context): raise NotImplementedError + # Debug flag management. + + def get_debug(self): + raise NotImplementedError + + def set_debug(self, enabled): + raise NotImplementedError + class AbstractEventLoopPolicy: """Abstract policy for accessing the event loop.""" diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index a3e7cdf..cf7b540 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -12,6 +12,8 @@ import concurrent.futures import functools import inspect import linecache +import os +import sys import traceback import weakref @@ -28,7 +30,8 @@ from .log import logger # before you define your coroutines. A downside of using this feature # is that tracebacks show entries for the CoroWrapper.__next__ method # when _DEBUG is true. -_DEBUG = False +_DEBUG = (not sys.flags.ignore_environment + and bool(os.environ.get('PYTHONASYNCIODEBUG'))) class CoroWrapper: |