Show More
@@ -66,10 +66,9 b" if __name__ == '__main__':" | |||
|
66 | 66 | from IPython.frontend.qt.kernelmanager import QtKernelManager |
|
67 | 67 | |
|
68 | 68 | # Create KernelManager |
|
69 | xreq_addr = ('127.0.0.1', 5575) | |
|
70 | sub_addr = ('127.0.0.1', 5576) | |
|
71 | rep_addr = ('127.0.0.1', 5577) | |
|
72 | kernel_manager = QtKernelManager(xreq_addr, sub_addr, rep_addr) | |
|
69 | kernel_manager = QtKernelManager(xreq_address = ('127.0.0.1', 5575), | |
|
70 | sub_address = ('127.0.0.1', 5576), | |
|
71 | rep_address = ('127.0.0.1', 5577)) | |
|
73 | 72 | kernel_manager.sub_channel.start() |
|
74 | 73 | kernel_manager.xreq_channel.start() |
|
75 | 74 |
@@ -25,13 +25,15 b' class MissingHandlerError(Exception):' | |||
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | class ZmqSocketChannel(Thread): |
|
28 | """ The base class for the channels that use ZMQ sockets. | |
|
29 | """ | |
|
28 | 30 | |
|
29 | socket = None | |
|
30 | ||
|
31 | def __init__(self, context, session, addr): | |
|
31 | def __init__(self, context, session, addr=None): | |
|
32 | 32 | self.context = context |
|
33 | 33 | self.session = session |
|
34 | 34 | self.addr = addr |
|
35 | self.socket = None | |
|
36 | ||
|
35 | 37 | super(ZmqSocketChannel, self).__init__() |
|
36 | 38 | self.daemon = True |
|
37 | 39 | |
@@ -41,7 +43,7 b' class SubSocketChannel(ZmqSocketChannel):' | |||
|
41 | 43 | handlers = None |
|
42 | 44 | _overriden_call_handler = None |
|
43 | 45 | |
|
44 | def __init__(self, context, session, addr): | |
|
46 | def __init__(self, context, session, addr=None): | |
|
45 | 47 | self.handlers = {} |
|
46 | 48 | super(SubSocketChannel, self).__init__(context, session, addr) |
|
47 | 49 | |
@@ -134,7 +136,7 b' class XReqSocketChannel(ZmqSocketChannel):' | |||
|
134 | 136 | handlers = None |
|
135 | 137 | _overriden_call_handler = None |
|
136 | 138 | |
|
137 | def __init__(self, context, session, addr): | |
|
139 | def __init__(self, context, session, addr=None): | |
|
138 | 140 | self.handlers = {} |
|
139 | 141 | self.handler_queue = Queue() |
|
140 | 142 | self.command_queue = Queue() |
@@ -249,16 +251,16 b' class RepSocketChannel(ZmqSocketChannel):' | |||
|
249 | 251 | |
|
250 | 252 | |
|
251 | 253 | class KernelManager(HasTraits): |
|
254 | """ Manages a kernel for a frontend. | |
|
252 | 255 |
|
|
253 | # The addresses to use for the various channels. Should be tuples of form | |
|
254 | # (ip_address, port). | |
|
255 | sub_address = Any | |
|
256 | xreq_address = Any | |
|
257 | rep_address = Any | |
|
258 | # FIXME: Add Tuple to Traitlets. | |
|
259 | #sub_address = Tuple(Str, Int) | |
|
260 | #xreq_address = Tuple(Str, Int) | |
|
261 | #rep_address = Tuple(Str, Int) | |
|
256 | The SUB channel is for the frontend to receive messages published by the | |
|
257 | kernel. | |
|
258 | ||
|
259 | The REQ channel is for the frontend to make requests of the kernel. | |
|
260 | ||
|
261 | The REP channel is for the kernel to request stdin (raw_input) from the | |
|
262 | frontend. | |
|
263 | """ | |
|
262 | 264 | |
|
263 | 265 | # The PyZMQ Context to use for communication with the kernel. |
|
264 | 266 | context = Instance(zmq.Context, ()) |
@@ -266,38 +268,39 b' class KernelManager(HasTraits):' | |||
|
266 | 268 | # The Session to use for communication with the kernel. |
|
267 | 269 | session = Instance(Session, ()) |
|
268 | 270 | |
|
271 | # The channels objects used for communication with the kernel. | |
|
272 | # FIXME: Add '_traitname_default' instantiation method to Traitlets. | |
|
273 | #sub_channel = Instance(SubSocketChannel) | |
|
274 | #xreq_channel = Instance(XReqSocketChannel) | |
|
275 | #rep_channel = Instance(RepSocketChannel) | |
|
276 | ||
|
269 | 277 | # The classes to use for the various channels. |
|
270 | 278 | sub_channel_class = Type(SubSocketChannel) |
|
271 | 279 | xreq_channel_class = Type(XReqSocketChannel) |
|
272 | 280 | rep_channel_class = Type(RepSocketChannel) |
|
273 | 281 | |
|
282 | # The addresses to use for the various channels. Should be tuples of form | |
|
283 | # (ip_address, port). | |
|
284 | #sub_address = DelegatesTo('sub_channel') | |
|
285 | #xreq_address = DelegatesTo('xreq_channel') | |
|
286 | #rep_address = DelegatesTo('rep_channel') | |
|
287 | ||
|
274 | 288 | # Protected traits. |
|
275 | 289 | _sub_channel = Any |
|
276 | 290 | _xreq_channel = Any |
|
277 | 291 | _rep_channel = Any |
|
278 | 292 | |
|
279 |
def __init__(self, |
|
|
293 | def __init__(self, **traits): | |
|
280 | 294 | super(KernelManager, self).__init__() |
|
281 | 295 | |
|
282 | self.xreq_address = xreq_address | |
|
283 | self.sub_address = sub_address | |
|
284 | self.rep_address = rep_address | |
|
285 | ||
|
286 | 296 | # FIXME: This should be the business of HasTraits. The convention is: |
|
287 | 297 | # HasTraits.__init__(self, **traits_to_be_initialized.) |
|
288 | 298 | for trait in traits: |
|
289 | 299 | setattr(self, trait, traits[trait]) |
|
290 | 300 | |
|
291 | 301 | def start_kernel(self): |
|
292 |
"""Start a localhost kernel |
|
|
293 | ||
|
294 | The SUB channel is for the frontend to receive messages published by | |
|
295 | the kernel. | |
|
296 | ||
|
297 | The REQ channel is for the frontend to make requests of the kernel. | |
|
298 | ||
|
299 | The REP channel is for the kernel to request stdin (raw_input) from | |
|
300 | the frontend. | |
|
302 | """Start a localhost kernel. If ports have been specified, use | |
|
303 | them. Otherwise, choose an open port at random. | |
|
301 | 304 | """ |
|
302 | 305 | |
|
303 | 306 | def kill_kernel(self): |
@@ -314,22 +317,43 b' class KernelManager(HasTraits):' | |||
|
314 | 317 | def sub_channel(self): |
|
315 | 318 | """Get the SUB socket channel object.""" |
|
316 | 319 | if self._sub_channel is None: |
|
317 | self._sub_channel = self.sub_channel_class( | |
|
318 | self.context, self.session, self.sub_address) | |
|
320 | self._sub_channel = self.sub_channel_class(self.context, | |
|
321 | self.session) | |
|
319 | 322 | return self._sub_channel |
|
320 | 323 | |
|
321 | 324 | @property |
|
322 | 325 | def xreq_channel(self): |
|
323 | 326 | """Get the REQ socket channel object to make requests of the kernel.""" |
|
324 | 327 | if self._xreq_channel is None: |
|
325 | self._xreq_channel = self.xreq_channel_class( | |
|
326 | self.context, self.session, self.xreq_address) | |
|
328 | self._xreq_channel = self.xreq_channel_class(self.context, | |
|
329 | self.session) | |
|
327 | 330 | return self._xreq_channel |
|
328 | 331 | |
|
329 | 332 | @property |
|
330 | 333 | def rep_channel(self): |
|
331 | 334 | """Get the REP socket channel object to handle stdin (raw_input).""" |
|
332 | 335 | if self._rep_channel is None: |
|
333 | self._rep_channel = self.rep_channel_class( | |
|
334 | self.context, self.session, self.rep_address) | |
|
336 | self._rep_channel = self.rep_channel_class(self.context, | |
|
337 | self.session) | |
|
335 | 338 | return self._rep_channel |
|
339 | ||
|
340 | def get_sub_address(self): | |
|
341 | return self.sub_channel.addr | |
|
342 | def set_sub_address(self, addr): | |
|
343 | self.sub_channel.addr = addr | |
|
344 | sub_address = property(get_sub_address, set_sub_address, | |
|
345 | doc="The address used by SUB socket channel.") | |
|
346 | ||
|
347 | def get_xreq_address(self): | |
|
348 | return self.xreq_channel.addr | |
|
349 | def set_xreq_address(self, addr): | |
|
350 | self.xreq_channel.addr = addr | |
|
351 | xreq_address = property(get_xreq_address, set_xreq_address, | |
|
352 | doc="The address used by XREQ socket channel.") | |
|
353 | ||
|
354 | def get_rep_address(self): | |
|
355 | return self.rep_channel.addr | |
|
356 | def set_rep_address(self, addr): | |
|
357 | self.rep_channel.addr = addr | |
|
358 | rep_address = property(get_rep_address, set_rep_address, | |
|
359 | doc="The address used by REP socket channel.") |
General Comments 0
You need to be logged in to leave comments.
Login now