Show More
@@ -28,7 +28,7 import zmq | |||
|
28 | 28 | from IPython.config.configurable import Configurable |
|
29 | 29 | from IPython.utils import io |
|
30 | 30 | from IPython.lib import pylabtools |
|
31 | from IPython.utils.traitlets import Instance | |
|
31 | from IPython.utils.traitlets import Instance, Float | |
|
32 | 32 | from entry_point import base_launch_kernel, make_argument_parser, make_kernel, \ |
|
33 | 33 | start_kernel |
|
34 | 34 | from iostream import OutStream |
@@ -52,6 +52,22 class Kernel(Configurable): | |||
|
52 | 52 | pub_socket = Instance('zmq.Socket') |
|
53 | 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 | 71 | def __init__(self, **kwargs): |
|
56 | 72 | super(Kernel, self).__init__(**kwargs) |
|
57 | 73 | |
@@ -101,7 +117,7 class Kernel(Configurable): | |||
|
101 | 117 | """ Start the kernel main loop. |
|
102 | 118 | """ |
|
103 | 119 | while True: |
|
104 |
time.sleep( |
|
|
120 | time.sleep(self._poll_interval) | |
|
105 | 121 | self.do_one_iteration() |
|
106 | 122 | |
|
107 | 123 | #--------------------------------------------------------------------------- |
@@ -202,7 +218,8 class Kernel(Configurable): | |||
|
202 | 218 | # FIXME: on rare occasions, the flush doesn't seem to make it to the |
|
203 | 219 | # clients... This seems to mitigate the problem, but we definitely need |
|
204 | 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 | 224 | self.reply_socket.send(ident, zmq.SNDMORE) |
|
208 | 225 | self.reply_socket.send_json(reply_msg) |
@@ -340,7 +357,8 class QtKernel(Kernel): | |||
|
340 | 357 | self.app.setQuitOnLastWindowClosed(False) |
|
341 | 358 | self.timer = QtCore.QTimer() |
|
342 | 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 | 362 | start_event_loop_qt4(self.app) |
|
345 | 363 | |
|
346 | 364 | |
@@ -360,7 +378,8 class WxKernel(Kernel): | |||
|
360 | 378 | def __init__(self, func): |
|
361 | 379 | wx.Frame.__init__(self, None, -1) |
|
362 | 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 | 383 | self.Bind(wx.EVT_TIMER, self.on_timer) |
|
365 | 384 | self.func = func |
|
366 | 385 | def on_timer(self, event): |
@@ -397,7 +416,8 class TkKernel(Kernel): | |||
|
397 | 416 | self.func = func |
|
398 | 417 | def on_timer(self): |
|
399 | 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 | 421 | def start(self): |
|
402 | 422 | self.on_timer() # Call it once to get things going. |
|
403 | 423 | self.app.mainloop() |
General Comments 0
You need to be logged in to leave comments.
Login now