##// END OF EJS Templates
Remove 5s wait on inactivity on GUI inputhook loops...
Remove 5s wait on inactivity on GUI inputhook loops The 5s (and 1s) waits were originally added in commit 5074878, but the 5 second wait meant if you left the console for 5+ minutes idle, it would take up to 5 seconds for a response to a keypress. This tradeoff of CPU cycles for battery life seems too far. Note that commit 5074878 was originally for wx, glut and pyglet are based on the wx version and came into existence after commit 5074878.

File last commit:

r11485:80378e13
r13125:f9e20986
Show More
test_kernel.py
91 lines | 3.1 KiB | text/x-python | PythonLexer
#-------------------------------------------------------------------------------
# Copyright (C) 2012 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from __future__ import print_function
# Standard library imports
from StringIO import StringIO
import sys
import unittest
# Local imports
from IPython.kernel.inprocess.blocking import BlockingInProcessKernelClient
from IPython.kernel.inprocess.manager import InProcessKernelManager
from IPython.kernel.inprocess.ipkernel import InProcessKernel
from IPython.testing.decorators import skipif_not_matplotlib
from IPython.utils.io import capture_output
from IPython.utils import py3compat
#-----------------------------------------------------------------------------
# Test case
#-----------------------------------------------------------------------------
class InProcessKernelTestCase(unittest.TestCase):
def setUp(self):
self.km = InProcessKernelManager()
self.km.start_kernel()
self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
self.kc.start_channels()
@skipif_not_matplotlib
def test_pylab(self):
""" Does pylab work in the in-process kernel?
"""
kc = self.kc
kc.execute('%pylab')
msg = get_stream_message(kc)
self.assert_('matplotlib' in msg['content']['data'])
def test_raw_input(self):
""" Does the in-process kernel handle raw_input correctly?
"""
io = StringIO('foobar\n')
sys_stdin = sys.stdin
sys.stdin = io
try:
if py3compat.PY3:
self.kc.execute('x = input()')
else:
self.kc.execute('x = raw_input()')
finally:
sys.stdin = sys_stdin
self.assertEqual(self.km.kernel.shell.user_ns.get('x'), 'foobar')
def test_stdout(self):
""" Does the in-process kernel correctly capture IO?
"""
kernel = InProcessKernel()
with capture_output() as io:
kernel.shell.run_cell('print("foo")')
self.assertEqual(io.stdout, 'foo\n')
kc = BlockingInProcessKernelClient(kernel=kernel)
kernel.frontends.append(kc)
kc.shell_channel.execute('print("bar")')
msg = get_stream_message(kc)
self.assertEqual(msg['content']['data'], 'bar\n')
#-----------------------------------------------------------------------------
# Utility functions
#-----------------------------------------------------------------------------
def get_stream_message(kernel_client, timeout=5):
""" Gets a single stream message synchronously from the sub channel.
"""
while True:
msg = kernel_client.get_iopub_msg(timeout=timeout)
if msg['header']['msg_type'] == 'stream':
return msg
if __name__ == '__main__':
unittest.main()