mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
asyncio, Tulip issue 105: in debug mode, log callbacks taking more than 100 ms
to be executed.
This commit is contained in:
parent
4932e14542
commit
0e6f52a211
2 changed files with 55 additions and 5 deletions
|
@ -969,6 +969,34 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
|
|||
with self.assertRaises(TypeError):
|
||||
self.loop.run_in_executor(None, coroutine_function)
|
||||
|
||||
@mock.patch('asyncio.base_events.logger')
|
||||
def test_log_slow_callbacks(self, m_logger):
|
||||
def stop_loop_cb(loop):
|
||||
loop.stop()
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop_loop_coro(loop):
|
||||
yield from ()
|
||||
loop.stop()
|
||||
|
||||
asyncio.set_event_loop(self.loop)
|
||||
self.loop.set_debug(True)
|
||||
self.loop.slow_callback_duration = 0.0
|
||||
|
||||
# slow callback
|
||||
self.loop.call_soon(stop_loop_cb, self.loop)
|
||||
self.loop.run_forever()
|
||||
fmt, *args = m_logger.warning.call_args[0]
|
||||
self.assertRegex(fmt % tuple(args),
|
||||
"^Executing Handle.*stop_loop_cb.* took .* seconds$")
|
||||
|
||||
# slow task
|
||||
asyncio.async(stop_loop_coro(self.loop), loop=self.loop)
|
||||
self.loop.run_forever()
|
||||
fmt, *args = m_logger.warning.call_args[0]
|
||||
self.assertRegex(fmt % tuple(args),
|
||||
"^Executing Task.*stop_loop_coro.* took .* seconds$")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue