##// END OF EJS Templates
relocate redundantly-named kernel files...
MinRK -
Show More
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
@@ -25,14 +25,14 b' from .kernelmanager import KernelManager, IOPubChannel, HBChannel, \\'
25
25
26
26
27 class BlockingChannelMixin(object):
27 class BlockingChannelMixin(object):
28
28
29 def __init__(self, *args, **kwds):
29 def __init__(self, *args, **kwds):
30 super(BlockingChannelMixin, self).__init__(*args, **kwds)
30 super(BlockingChannelMixin, self).__init__(*args, **kwds)
31 self._in_queue = Queue.Queue()
31 self._in_queue = Queue.Queue()
32
32
33 def call_handlers(self, msg):
33 def call_handlers(self, msg):
34 self._in_queue.put(msg)
34 self._in_queue.put(msg)
35
35
36 def get_msg(self, block=True, timeout=None):
36 def get_msg(self, block=True, timeout=None):
37 """ Gets a message if there is one that is ready. """
37 """ Gets a message if there is one that is ready. """
38 if timeout is None:
38 if timeout is None:
@@ -40,7 +40,7 b' class BlockingChannelMixin(object):'
40 # behavior, so wait for a week instead
40 # behavior, so wait for a week instead
41 timeout = 604800
41 timeout = 604800
42 return self._in_queue.get(block, timeout)
42 return self._in_queue.get(block, timeout)
43
43
44 def get_msgs(self):
44 def get_msgs(self):
45 """ Get all messages that are currently ready. """
45 """ Get all messages that are currently ready. """
46 msgs = []
46 msgs = []
@@ -50,7 +50,7 b' class BlockingChannelMixin(object):'
50 except Queue.Empty:
50 except Queue.Empty:
51 break
51 break
52 return msgs
52 return msgs
53
53
54 def msg_ready(self):
54 def msg_ready(self):
55 """ Is there a message that has been received? """
55 """ Is there a message that has been received? """
56 return not self._in_queue.empty()
56 return not self._in_queue.empty()
@@ -69,7 +69,7 b' class BlockingStdInChannel(BlockingChannelMixin, StdInChannel):'
69
69
70
70
71 class BlockingHBChannel(HBChannel):
71 class BlockingHBChannel(HBChannel):
72
72
73 # This kernel needs quicker monitoring, shorten to 1 sec.
73 # This kernel needs quicker monitoring, shorten to 1 sec.
74 # less than 0.5s is unreliable, and will get occasional
74 # less than 0.5s is unreliable, and will get occasional
75 # false reports of missed beats.
75 # false reports of missed beats.
@@ -87,4 +87,3 b' class BlockingKernelManager(KernelManager):'
87 iopub_channel_class = Type(BlockingIOPubChannel)
87 iopub_channel_class = Type(BlockingIOPubChannel)
88 stdin_channel_class = Type(BlockingStdInChannel)
88 stdin_channel_class = Type(BlockingStdInChannel)
89 hb_channel_class = Type(BlockingHBChannel)
89 hb_channel_class = Type(BlockingHBChannel)
90
1 NO CONTENT: file renamed from IPython/kernel/ioloopkernelmanager.py to IPython/kernel/ioloop/manager.py
NO CONTENT: file renamed from IPython/kernel/ioloopkernelmanager.py to IPython/kernel/ioloop/manager.py
1 NO CONTENT: file renamed from IPython/kernel/ioloopkernelrestarter.py to IPython/kernel/ioloop/restarter.py
NO CONTENT: file renamed from IPython/kernel/ioloopkernelrestarter.py to IPython/kernel/ioloop/restarter.py
@@ -128,7 +128,7 b' class ZMQSocketChannel(Thread):'
128 address = "tcp://%s:%i" % address
128 address = "tcp://%s:%i" % address
129 self._address = address
129 self._address = address
130 atexit.register(self._notice_exit)
130 atexit.register(self._notice_exit)
131
131
132 def _notice_exit(self):
132 def _notice_exit(self):
133 self._exiting = True
133 self._exiting = True
134
134
@@ -169,11 +169,11 b' class ZMQSocketChannel(Thread):'
169
169
170 def _queue_send(self, msg):
170 def _queue_send(self, msg):
171 """Queue a message to be sent from the IOLoop's thread.
171 """Queue a message to be sent from the IOLoop's thread.
172
172
173 Parameters
173 Parameters
174 ----------
174 ----------
175 msg : message to send
175 msg : message to send
176
176
177 This is threadsafe, as it uses IOLoop.add_callback to give the loop's
177 This is threadsafe, as it uses IOLoop.add_callback to give the loop's
178 thread control of the action.
178 thread control of the action.
179 """
179 """
@@ -188,7 +188,7 b' class ZMQSocketChannel(Thread):'
188 """
188 """
189 ident,smsg = self.session.feed_identities(msg)
189 ident,smsg = self.session.feed_identities(msg)
190 self.call_handlers(self.session.unserialize(smsg))
190 self.call_handlers(self.session.unserialize(smsg))
191
191
192
192
193
193
194 class ShellChannel(ZMQSocketChannel):
194 class ShellChannel(ZMQSocketChannel):
@@ -260,7 +260,7 b' class ShellChannel(ZMQSocketChannel):'
260 allow_stdin : bool, optional (default self.allow_stdin)
260 allow_stdin : bool, optional (default self.allow_stdin)
261 Flag for whether the kernel can send stdin requests to frontends.
261 Flag for whether the kernel can send stdin requests to frontends.
262
262
263 Some frontends (e.g. the Notebook) do not support stdin requests.
263 Some frontends (e.g. the Notebook) do not support stdin requests.
264 If raw_input is called from code executed from such a frontend, a
264 If raw_input is called from code executed from such a frontend, a
265 StdinNotImplementedError will be raised.
265 StdinNotImplementedError will be raised.
266
266
@@ -274,8 +274,8 b' class ShellChannel(ZMQSocketChannel):'
274 user_expressions = {}
274 user_expressions = {}
275 if allow_stdin is None:
275 if allow_stdin is None:
276 allow_stdin = self.allow_stdin
276 allow_stdin = self.allow_stdin
277
277
278
278
279 # Don't waste network traffic if inputs are invalid
279 # Don't waste network traffic if inputs are invalid
280 if not isinstance(code, basestring):
280 if not isinstance(code, basestring):
281 raise ValueError('code %r must be a string' % code)
281 raise ValueError('code %r must be a string' % code)
@@ -542,17 +542,17 b' class HBChannel(ZMQSocketChannel):'
542 self.socket = self.context.socket(zmq.REQ)
542 self.socket = self.context.socket(zmq.REQ)
543 self.socket.setsockopt(zmq.LINGER, 0)
543 self.socket.setsockopt(zmq.LINGER, 0)
544 self.socket.connect(self.address)
544 self.socket.connect(self.address)
545
545
546 self.poller.register(self.socket, zmq.POLLIN)
546 self.poller.register(self.socket, zmq.POLLIN)
547
547
548 def _poll(self, start_time):
548 def _poll(self, start_time):
549 """poll for heartbeat replies until we reach self.time_to_dead.
549 """poll for heartbeat replies until we reach self.time_to_dead.
550
550
551 Ignores interrupts, and returns the result of poll(), which
551 Ignores interrupts, and returns the result of poll(), which
552 will be an empty list if no messages arrived before the timeout,
552 will be an empty list if no messages arrived before the timeout,
553 or the event tuple if there is a message to receive.
553 or the event tuple if there is a message to receive.
554 """
554 """
555
555
556 until_dead = self.time_to_dead - (time.time() - start_time)
556 until_dead = self.time_to_dead - (time.time() - start_time)
557 # ensure poll at least once
557 # ensure poll at least once
558 until_dead = max(until_dead, 1e-3)
558 until_dead = max(until_dead, 1e-3)
@@ -583,13 +583,13 b' class HBChannel(ZMQSocketChannel):'
583 self._create_socket()
583 self._create_socket()
584 self._running = True
584 self._running = True
585 self._beating = True
585 self._beating = True
586
586
587 while self._running:
587 while self._running:
588 if self._pause:
588 if self._pause:
589 # just sleep, and skip the rest of the loop
589 # just sleep, and skip the rest of the loop
590 time.sleep(self.time_to_dead)
590 time.sleep(self.time_to_dead)
591 continue
591 continue
592
592
593 since_last_heartbeat = 0.0
593 since_last_heartbeat = 0.0
594 # io.rprint('Ping from HB channel') # dbg
594 # io.rprint('Ping from HB channel') # dbg
595 # no need to catch EFSM here, because the previous event was
595 # no need to catch EFSM here, because the previous event was
@@ -683,11 +683,11 b' class KernelManager(Configurable):'
683
683
684 # The kernel process with which the KernelManager is communicating.
684 # The kernel process with which the KernelManager is communicating.
685 # generally a Popen instance
685 # generally a Popen instance
686 kernel = Any()
686 kernel = Any()
687
687
688 kernel_cmd = List(Unicode, config=True,
688 kernel_cmd = List(Unicode, config=True,
689 help="""The Popen Command to launch the kernel.
689 help="""The Popen Command to launch the kernel.
690 Override this if you have a custom
690 Override this if you have a custom
691 """
691 """
692 )
692 )
693
693
@@ -698,7 +698,7 b' class KernelManager(Configurable):'
698
698
699 # The addresses for the communication channels.
699 # The addresses for the communication channels.
700 connection_file = Unicode('')
700 connection_file = Unicode('')
701
701
702 transport = CaselessStrEnum(['tcp', 'ipc'], default_value='tcp', config=True)
702 transport = CaselessStrEnum(['tcp', 'ipc'], default_value='tcp', config=True)
703
703
704 ip = Unicode(LOCALHOST, config=True,
704 ip = Unicode(LOCALHOST, config=True,
@@ -756,7 +756,7 b' class KernelManager(Configurable):'
756
756
757 This will create the channels if they do not exist and then start
757 This will create the channels if they do not exist and then start
758 them (their activity runs in a thread). If port numbers of 0 are
758 them (their activity runs in a thread). If port numbers of 0 are
759 being used (random ports) then you must first call
759 being used (random ports) then you must first call
760 :method:`start_kernel`. If the channels have been stopped and you
760 :method:`start_kernel`. If the channels have been stopped and you
761 call this, :class:`RuntimeError` will be raised.
761 call this, :class:`RuntimeError` will be raised.
762 """
762 """
@@ -844,10 +844,10 b' class KernelManager(Configurable):'
844 #--------------------------------------------------------------------------
844 #--------------------------------------------------------------------------
845 # Connection and ipc file management
845 # Connection and ipc file management
846 #--------------------------------------------------------------------------
846 #--------------------------------------------------------------------------
847
847
848 def cleanup_connection_file(self):
848 def cleanup_connection_file(self):
849 """Cleanup connection file *if we wrote it*
849 """Cleanup connection file *if we wrote it*
850
850
851 Will not raise if the connection file was already removed somehow.
851 Will not raise if the connection file was already removed somehow.
852 """
852 """
853 if self._connection_file_written:
853 if self._connection_file_written:
@@ -857,7 +857,7 b' class KernelManager(Configurable):'
857 os.remove(self.connection_file)
857 os.remove(self.connection_file)
858 except (IOError, OSError, AttributeError):
858 except (IOError, OSError, AttributeError):
859 pass
859 pass
860
860
861 def cleanup_ipc_files(self):
861 def cleanup_ipc_files(self):
862 """Cleanup ipc files if we wrote them."""
862 """Cleanup ipc files if we wrote them."""
863 if self.transport != 'ipc':
863 if self.transport != 'ipc':
@@ -883,7 +883,7 b' class KernelManager(Configurable):'
883 self.iopub_port = cfg['iopub_port']
883 self.iopub_port = cfg['iopub_port']
884 self.hb_port = cfg['hb_port']
884 self.hb_port = cfg['hb_port']
885 self.session.key = str_to_bytes(cfg['key'])
885 self.session.key = str_to_bytes(cfg['key'])
886
886
887 def write_connection_file(self):
887 def write_connection_file(self):
888 """Write connection info to JSON dict in self.connection_file."""
888 """Write connection info to JSON dict in self.connection_file."""
889 if self._connection_file_written:
889 if self._connection_file_written:
@@ -897,7 +897,7 b' class KernelManager(Configurable):'
897 self.stdin_port = cfg['stdin_port']
897 self.stdin_port = cfg['stdin_port']
898 self.iopub_port = cfg['iopub_port']
898 self.iopub_port = cfg['iopub_port']
899 self.hb_port = cfg['hb_port']
899 self.hb_port = cfg['hb_port']
900
900
901 self._connection_file_written = True
901 self._connection_file_written = True
902
902
903 #--------------------------------------------------------------------------
903 #--------------------------------------------------------------------------
@@ -926,14 +926,14 b' class KernelManager(Configurable):'
926 ns = dict(connection_file=self.connection_file)
926 ns = dict(connection_file=self.connection_file)
927 ns.update(self._launch_args)
927 ns.update(self._launch_args)
928 return [ c.format(**ns) for c in cmd ]
928 return [ c.format(**ns) for c in cmd ]
929
929
930 def _launch_kernel(self, kernel_cmd, **kw):
930 def _launch_kernel(self, kernel_cmd, **kw):
931 """actually launch the kernel
931 """actually launch the kernel
932
932
933 override in a subclass to launch kernel subprocesses differently
933 override in a subclass to launch kernel subprocesses differently
934 """
934 """
935 return launch_kernel(kernel_cmd, **kw)
935 return launch_kernel(kernel_cmd, **kw)
936
936
937 def start_kernel(self, **kw):
937 def start_kernel(self, **kw):
938 """Starts a kernel on this host in a separate process.
938 """Starts a kernel on this host in a separate process.
939
939
@@ -952,7 +952,7 b' class KernelManager(Configurable):'
952 "configured properly. "
952 "configured properly. "
953 "Currently valid addresses are: %s"%LOCAL_IPS
953 "Currently valid addresses are: %s"%LOCAL_IPS
954 )
954 )
955
955
956 # write connection file / get default ports
956 # write connection file / get default ports
957 self.write_connection_file()
957 self.write_connection_file()
958
958
@@ -967,7 +967,7 b' class KernelManager(Configurable):'
967 self.start_restarter()
967 self.start_restarter()
968
968
969 def shutdown_kernel(self, now=False, restart=False):
969 def shutdown_kernel(self, now=False, restart=False):
970 """Attempts to the stop the kernel process cleanly.
970 """Attempts to the stop the kernel process cleanly.
971
971
972 This attempts to shutdown the kernels cleanly by:
972 This attempts to shutdown the kernels cleanly by:
973
973
@@ -1144,4 +1144,3 b' IOPubChannelABC.register(IOPubChannel)'
1144 HBChannelABC.register(HBChannel)
1144 HBChannelABC.register(HBChannel)
1145 StdInChannelABC.register(StdInChannel)
1145 StdInChannelABC.register(StdInChannel)
1146 KernelManagerABC.register(KernelManager)
1146 KernelManagerABC.register(KernelManager)
1147
@@ -223,4 +223,3 b' class KernelManagerABC(object):'
223 @abc.abstractmethod
223 @abc.abstractmethod
224 def is_alive(self):
224 def is_alive(self):
225 pass
225 pass
226
General Comments 0
You need to be logged in to leave comments. Login now