##// END OF EJS Templates
Make exec/event loop times configurable. Set exec one to 500 microseconds.
Fernando Perez -
Show More
@@ -28,7 +28,7 b' import zmq'
28 from IPython.config.configurable import Configurable
28 from IPython.config.configurable import Configurable
29 from IPython.utils import io
29 from IPython.utils import io
30 from IPython.lib import pylabtools
30 from IPython.lib import pylabtools
31 from IPython.utils.traitlets import Instance
31 from IPython.utils.traitlets import Instance, Float
32 from entry_point import base_launch_kernel, make_argument_parser, make_kernel, \
32 from entry_point import base_launch_kernel, make_argument_parser, make_kernel, \
33 start_kernel
33 start_kernel
34 from iostream import OutStream
34 from iostream import OutStream
@@ -52,6 +52,22 b' class Kernel(Configurable):'
52 pub_socket = Instance('zmq.Socket')
52 pub_socket = Instance('zmq.Socket')
53 req_socket = Instance('zmq.Socket')
53 req_socket = Instance('zmq.Socket')
54
54
55 # Private interface
56
57 # Time to sleep after flushing the stdout/err buffers in each execute
58 # cycle. While this introduces a hard limit on the minimal latency of the
59 # execute cycle, it helps prevent output synchronization problems for
60 # clients.
61 # Units are in seconds. The minimum zmq latency on local host is probably
62 # ~150 microseconds, set this to 500us for now. We may need to increase it
63 # a little if it's not enough after more interactive testing.
64 _execute_sleep = Float(0.0005, config=True)
65
66 # Frequency of the kernel's event loop.
67 # Units are in seconds, kernel subclasses for GUI toolkits may need to
68 # adapt to milliseconds.
69 _poll_interval = Float(0.05, config=True)
70
55 def __init__(self, **kwargs):
71 def __init__(self, **kwargs):
56 super(Kernel, self).__init__(**kwargs)
72 super(Kernel, self).__init__(**kwargs)
57
73
@@ -101,7 +117,7 b' class Kernel(Configurable):'
101 """ Start the kernel main loop.
117 """ Start the kernel main loop.
102 """
118 """
103 while True:
119 while True:
104 time.sleep(0.05)
120 time.sleep(self._poll_interval)
105 self.do_one_iteration()
121 self.do_one_iteration()
106
122
107 #---------------------------------------------------------------------------
123 #---------------------------------------------------------------------------
@@ -202,7 +218,8 b' class Kernel(Configurable):'
202 # FIXME: on rare occasions, the flush doesn't seem to make it to the
218 # FIXME: on rare occasions, the flush doesn't seem to make it to the
203 # clients... This seems to mitigate the problem, but we definitely need
219 # clients... This seems to mitigate the problem, but we definitely need
204 # to better understand what's going on.
220 # to better understand what's going on.
205 time.sleep(0.05)
221 if self._execute_sleep:
222 time.sleep(self._execute_sleep)
206
223
207 self.reply_socket.send(ident, zmq.SNDMORE)
224 self.reply_socket.send(ident, zmq.SNDMORE)
208 self.reply_socket.send_json(reply_msg)
225 self.reply_socket.send_json(reply_msg)
@@ -340,7 +357,8 b' class QtKernel(Kernel):'
340 self.app.setQuitOnLastWindowClosed(False)
357 self.app.setQuitOnLastWindowClosed(False)
341 self.timer = QtCore.QTimer()
358 self.timer = QtCore.QTimer()
342 self.timer.timeout.connect(self.do_one_iteration)
359 self.timer.timeout.connect(self.do_one_iteration)
343 self.timer.start(50)
360 # Units for the timer are in milliseconds
361 self.timer.start(1000*self._poll_interval)
344 start_event_loop_qt4(self.app)
362 start_event_loop_qt4(self.app)
345
363
346
364
@@ -360,7 +378,8 b' class WxKernel(Kernel):'
360 def __init__(self, func):
378 def __init__(self, func):
361 wx.Frame.__init__(self, None, -1)
379 wx.Frame.__init__(self, None, -1)
362 self.timer = wx.Timer(self)
380 self.timer = wx.Timer(self)
363 self.timer.Start(50)
381 # Units for the timer are in milliseconds
382 self.timer.Start(1000*self._poll_interval)
364 self.Bind(wx.EVT_TIMER, self.on_timer)
383 self.Bind(wx.EVT_TIMER, self.on_timer)
365 self.func = func
384 self.func = func
366 def on_timer(self, event):
385 def on_timer(self, event):
@@ -397,7 +416,8 b' class TkKernel(Kernel):'
397 self.func = func
416 self.func = func
398 def on_timer(self):
417 def on_timer(self):
399 self.func()
418 self.func()
400 self.app.after(50, self.on_timer)
419 # Units for the timer are in milliseconds
420 self.app.after(1000*self._poll_interval, self.on_timer)
401 def start(self):
421 def start(self):
402 self.on_timer() # Call it once to get things going.
422 self.on_timer() # Call it once to get things going.
403 self.app.mainloop()
423 self.app.mainloop()
General Comments 0
You need to be logged in to leave comments. Login now