Show More
@@ -16,7 +16,8 b' from zmq import POLLIN, POLLOUT, POLLERR' | |||||
16 | from zmq.eventloop import ioloop |
|
16 | from zmq.eventloop import ioloop | |
17 |
|
17 | |||
18 | # Local imports. |
|
18 | # Local imports. | |
19 |
from IPython.utils.traitlets import HasTraits, Any, Int, Instance, Str, |
|
19 | from IPython.utils.traitlets import HasTraits, Any, Bool, Int, Instance, Str, \ | |
|
20 | Type | |||
20 | from session import Session |
|
21 | from session import Session | |
21 |
|
22 | |||
22 |
|
23 | |||
@@ -296,6 +297,9 b' class KernelManager(HasTraits):' | |||||
296 | frontend. |
|
297 | frontend. | |
297 | """ |
|
298 | """ | |
298 |
|
299 | |||
|
300 | # Whether the kernel manager is currently listening on its channels. | |||
|
301 | is_listening = Bool(False) | |||
|
302 | ||||
299 | # The PyZMQ Context to use for communication with the kernel. |
|
303 | # The PyZMQ Context to use for communication with the kernel. | |
300 | context = Instance(zmq.Context, ()) |
|
304 | context = Instance(zmq.Context, ()) | |
301 |
|
305 | |||
@@ -320,27 +324,51 b' class KernelManager(HasTraits):' | |||||
320 | for trait in traits: |
|
324 | for trait in traits: | |
321 | setattr(self, trait, traits[trait]) |
|
325 | setattr(self, trait, traits[trait]) | |
322 |
|
326 | |||
|
327 | def start_listening(self): | |||
|
328 | """Start listening on the specified ports. If already listening, raises | |||
|
329 | a RuntimeError. | |||
|
330 | """ | |||
|
331 | if self.is_listening: | |||
|
332 | raise RuntimeError("Cannot start listening. Already listening!") | |||
|
333 | else: | |||
|
334 | self.is_listening = True | |||
|
335 | self.sub_channel.start() | |||
|
336 | self.xreq_channel.start() | |||
|
337 | self.rep_channel.start() | |||
|
338 | ||||
|
339 | def stop_listening(self): | |||
|
340 | """Stop listening. If not listening, does nothing. """ | |||
|
341 | if self.is_listening: | |||
|
342 | self.is_listening = False | |||
|
343 | self.sub_channel.stop() | |||
|
344 | self.xreq_channel.stop() | |||
|
345 | self.rep_channel.stop() | |||
|
346 | ||||
323 | def start_kernel(self): |
|
347 | def start_kernel(self): | |
324 | """Start a localhost kernel. If ports have been specified, use |
|
348 | """Start a localhost kernel. If ports have been specified, use them. | |
325 |
|
|
349 | Otherwise, choose an open port at random. | |
326 | """ |
|
350 | """ | |
327 | self.sub_channel.start() |
|
351 | # TODO: start a kernel. | |
328 |
self. |
|
352 | self.start_listening() | |
329 | self.rep_channel.start() |
|
|||
330 |
|
353 | |||
331 | def kill_kernel(self): |
|
354 | def kill_kernel(self): | |
332 | """Kill the running kernel. |
|
355 | """Kill the running kernel. | |
333 | """ |
|
356 | """ | |
334 | self.sub_channel.stop() |
|
357 | # TODO: kill the kernel. | |
335 |
self. |
|
358 | self.stop_listening() | |
336 | self.rep_channel.stop() |
|
|||
337 |
|
359 | |||
|
360 | @property | |||
338 | def is_alive(self): |
|
361 | def is_alive(self): | |
339 |
""" |
|
362 | """ Returns whether the kernel is alive. """ | |
340 | return True |
|
363 | if self.is_listening: | |
|
364 | # TODO: check if alive. | |||
|
365 | return True | |||
|
366 | else: | |||
|
367 | return False | |||
341 |
|
368 | |||
342 | def signal_kernel(self, signum): |
|
369 | def signal_kernel(self, signum): | |
343 | """Send signum to the kernel.""" |
|
370 | """Send signum to the kernel.""" | |
|
371 | # TODO: signal the kernel. | |||
344 |
|
372 | |||
345 | #-------------------------------------------------------------------------- |
|
373 | #-------------------------------------------------------------------------- | |
346 | # Channels used for communication with the kernel: |
|
374 | # Channels used for communication with the kernel: | |
@@ -371,7 +399,7 b' class KernelManager(HasTraits):' | |||||
371 | return self._rep_channel |
|
399 | return self._rep_channel | |
372 |
|
400 | |||
373 | #-------------------------------------------------------------------------- |
|
401 | #-------------------------------------------------------------------------- | |
374 | # Channel addresses: |
|
402 | # Channel address attributes: | |
375 | #-------------------------------------------------------------------------- |
|
403 | #-------------------------------------------------------------------------- | |
376 |
|
404 | |||
377 | def get_sub_address(self): |
|
405 | def get_sub_address(self): |
General Comments 0
You need to be logged in to leave comments.
Login now