diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-11 09:58:33 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-11 09:58:33 (GMT) |
commit | 770e48d0174726e339074cfffa68fce23768aab5 (patch) | |
tree | 807e997af92d392c29b5e060588460d42d3aec00 /Lib/asyncio | |
parent | 3740d589f7e1737da480b2730161cb835b8dd55c (diff) | |
download | cpython-770e48d0174726e339074cfffa68fce23768aab5.zip cpython-770e48d0174726e339074cfffa68fce23768aab5.tar.gz cpython-770e48d0174726e339074cfffa68fce23768aab5.tar.bz2 |
asyncio: sync with Tulip
* Tulip issue #182: Improve logs of BaseEventLoop._run_once()
- Don't log non-blocking poll
- Only log polling with a timeout if it gets events or if it timed out after
more than 1 second.
* Fix some pyflakes warnings: remove unused imports
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/base_events.py | 21 | ||||
-rw-r--r-- | Lib/asyncio/streams.py | 1 | ||||
-rw-r--r-- | Lib/asyncio/tasks.py | 1 |
3 files changed, 14 insertions, 9 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index f6d7a58..3951fb7 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -882,19 +882,26 @@ class BaseEventLoop(events.AbstractEventLoop): when = self._scheduled[0]._when timeout = max(0, when - self.time()) - if self._debug: + if self._debug and timeout != 0: t0 = self.time() event_list = self._selector.select(timeout) dt = self.time() - t0 - if dt >= 1: + if dt >= 1.0: level = logging.INFO else: level = logging.DEBUG - if timeout is not None: - logger.log(level, 'poll %.3f took %.3f seconds', - timeout, dt) - else: - logger.log(level, 'poll took %.3f seconds', dt) + nevent = len(event_list) + if timeout is None: + logger.log(level, 'poll took %.3f ms: %s events', + dt * 1e3, nevent) + elif nevent: + logger.log(level, + 'poll %.3f ms took %.3f ms: %s events', + timeout * 1e3, dt * 1e3, nevent) + elif dt >= 1.0: + logger.log(level, + 'poll %.3f ms took %.3f ms: timeout', + timeout * 1e3, dt * 1e3) else: event_list = self._selector.select(timeout) self._process_events(event_list) diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index 9bde218..9b654cd 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -14,7 +14,6 @@ from . import coroutines from . import events from . import futures from . import protocols -from . import tasks from .coroutines import coroutine diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 3d7e5a4..78b4c4d 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -18,7 +18,6 @@ from . import coroutines from . import events from . import futures from .coroutines import coroutine -from .log import logger _PY34 = (sys.version_info >= (3, 4)) |