mirror of
https://github.com/python/cpython.git
synced 2025-07-30 06:34:15 +00:00
(Merge 3.4) 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
This commit is contained in:
commit
39578d8510
6 changed files with 20 additions and 16 deletions
|
@ -882,19 +882,26 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
when = self._scheduled[0]._when
|
when = self._scheduled[0]._when
|
||||||
timeout = max(0, when - self.time())
|
timeout = max(0, when - self.time())
|
||||||
|
|
||||||
if self._debug:
|
if self._debug and timeout != 0:
|
||||||
t0 = self.time()
|
t0 = self.time()
|
||||||
event_list = self._selector.select(timeout)
|
event_list = self._selector.select(timeout)
|
||||||
dt = self.time() - t0
|
dt = self.time() - t0
|
||||||
if dt >= 1:
|
if dt >= 1.0:
|
||||||
level = logging.INFO
|
level = logging.INFO
|
||||||
else:
|
else:
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
if timeout is not None:
|
nevent = len(event_list)
|
||||||
logger.log(level, 'poll %.3f took %.3f seconds',
|
if timeout is None:
|
||||||
timeout, dt)
|
logger.log(level, 'poll took %.3f ms: %s events',
|
||||||
else:
|
dt * 1e3, nevent)
|
||||||
logger.log(level, 'poll took %.3f seconds', dt)
|
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:
|
else:
|
||||||
event_list = self._selector.select(timeout)
|
event_list = self._selector.select(timeout)
|
||||||
self._process_events(event_list)
|
self._process_events(event_list)
|
||||||
|
|
|
@ -14,7 +14,6 @@ from . import coroutines
|
||||||
from . import events
|
from . import events
|
||||||
from . import futures
|
from . import futures
|
||||||
from . import protocols
|
from . import protocols
|
||||||
from . import tasks
|
|
||||||
from .coroutines import coroutine
|
from .coroutines import coroutine
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ from . import coroutines
|
||||||
from . import events
|
from . import events
|
||||||
from . import futures
|
from . import futures
|
||||||
from .coroutines import coroutine
|
from .coroutines import coroutine
|
||||||
from .log import logger
|
|
||||||
|
|
||||||
_PY34 = (sys.version_info >= (3, 4))
|
_PY34 = (sys.version_info >= (3, 4))
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ from test.support import IPV6_ENABLED
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from asyncio import base_events
|
from asyncio import base_events
|
||||||
from asyncio import events
|
|
||||||
from asyncio import constants
|
from asyncio import constants
|
||||||
from asyncio import test_utils
|
from asyncio import test_utils
|
||||||
|
|
||||||
|
@ -26,6 +25,7 @@ class BaseEventLoopTests(test_utils.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.loop = base_events.BaseEventLoop()
|
self.loop = base_events.BaseEventLoop()
|
||||||
self.loop._selector = mock.Mock()
|
self.loop._selector = mock.Mock()
|
||||||
|
self.loop._selector.select.return_value = ()
|
||||||
self.set_event_loop(self.loop)
|
self.set_event_loop(self.loop)
|
||||||
|
|
||||||
def test_not_implemented(self):
|
def test_not_implemented(self):
|
||||||
|
|
|
@ -715,7 +715,7 @@ class EventLoopTestsMixin:
|
||||||
with self.assertRaisesRegex(ValueError,
|
with self.assertRaisesRegex(ValueError,
|
||||||
'path and sock can not be specified '
|
'path and sock can not be specified '
|
||||||
'at the same time'):
|
'at the same time'):
|
||||||
server = self.loop.run_until_complete(f)
|
self.loop.run_until_complete(f)
|
||||||
|
|
||||||
def _create_ssl_context(self, certfile, keyfile=None):
|
def _create_ssl_context(self, certfile, keyfile=None):
|
||||||
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""Tests for tasks.py."""
|
"""Tests for tasks.py."""
|
||||||
|
|
||||||
import os.path
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
|
@ -1640,9 +1639,9 @@ class TaskTests(test_utils.TestCase):
|
||||||
asyncio.coroutines._DEBUG = debug
|
asyncio.coroutines._DEBUG = debug
|
||||||
|
|
||||||
tb_filename = __file__
|
tb_filename = __file__
|
||||||
tb_lineno = sys._getframe().f_lineno + 1
|
tb_lineno = sys._getframe().f_lineno + 2
|
||||||
coro = coro_noop()
|
# create a coroutine object but don't use it
|
||||||
coro = None
|
coro_noop()
|
||||||
support.gc_collect()
|
support.gc_collect()
|
||||||
|
|
||||||
self.assertTrue(m_log.error.called)
|
self.assertTrue(m_log.error.called)
|
||||||
|
@ -1652,7 +1651,7 @@ class TaskTests(test_utils.TestCase):
|
||||||
r'Coroutine object created at \(most recent call last\):\n'
|
r'Coroutine object created at \(most recent call last\):\n'
|
||||||
r'.*\n'
|
r'.*\n'
|
||||||
r' File "%s", line %s, in test_coroutine_never_yielded\n'
|
r' File "%s", line %s, in test_coroutine_never_yielded\n'
|
||||||
r' coro = coro_noop\(\)$'
|
r' coro_noop\(\)$'
|
||||||
% (re.escape(coro_noop.__qualname__),
|
% (re.escape(coro_noop.__qualname__),
|
||||||
re.escape(func_filename), func_lineno,
|
re.escape(func_filename), func_lineno,
|
||||||
re.escape(tb_filename), tb_lineno))
|
re.escape(tb_filename), tb_lineno))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue