Show More
@@ -124,7 +124,7 b' class InProcessKernel(IPythonKernel):' | |||||
124 |
|
124 | |||
125 | def _session_default(self): |
|
125 | def _session_default(self): | |
126 | from IPython.kernel.zmq.session import Session |
|
126 | from IPython.kernel.zmq.session import Session | |
127 | return Session(parent=self) |
|
127 | return Session(parent=self, key=b'') | |
128 |
|
128 | |||
129 | def _shell_class_default(self): |
|
129 | def _shell_class_default(self): | |
130 | return InProcessInteractiveShell |
|
130 | return InProcessInteractiveShell |
@@ -1,23 +1,13 b'' | |||||
1 | """A kernel manager for in-process kernels.""" |
|
1 | """A kernel manager for in-process kernels.""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | # Copyright (c) IPython Development Team. | |
4 | # Copyright (C) 2013 The IPython Development Team |
|
4 | # Distributed under the terms of the Modified BSD License. | |
5 | # |
|
|||
6 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
7 | # the file COPYING, distributed as part of this software. |
|
|||
8 | #----------------------------------------------------------------------------- |
|
|||
9 |
|
||||
10 | #----------------------------------------------------------------------------- |
|
|||
11 | # Imports |
|
|||
12 | #----------------------------------------------------------------------------- |
|
|||
13 |
|
5 | |||
14 | from IPython.utils.traitlets import Instance, DottedObjectName |
|
6 | from IPython.utils.traitlets import Instance, DottedObjectName | |
15 | from IPython.kernel.managerabc import KernelManagerABC |
|
7 | from IPython.kernel.managerabc import KernelManagerABC | |
16 | from IPython.kernel.manager import KernelManager |
|
8 | from IPython.kernel.manager import KernelManager | |
|
9 | from IPython.kernel.zmq.session import Session | |||
17 |
|
10 | |||
18 | #----------------------------------------------------------------------------- |
|
|||
19 | # Main kernel manager class |
|
|||
20 | #----------------------------------------------------------------------------- |
|
|||
21 |
|
11 | |||
22 | class InProcessKernelManager(KernelManager): |
|
12 | class InProcessKernelManager(KernelManager): | |
23 | """A manager for an in-process kernel. |
|
13 | """A manager for an in-process kernel. | |
@@ -33,14 +23,18 b' class InProcessKernelManager(KernelManager):' | |||||
33 | kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel') |
|
23 | kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel') | |
34 | # the client class for KM.client() shortcut |
|
24 | # the client class for KM.client() shortcut | |
35 | client_class = DottedObjectName('IPython.kernel.inprocess.BlockingInProcessKernelClient') |
|
25 | client_class = DottedObjectName('IPython.kernel.inprocess.BlockingInProcessKernelClient') | |
36 |
|
26 | |||
|
27 | def _session_default(self): | |||
|
28 | # don't sign in-process messages | |||
|
29 | return Session(key=b'', parent=self) | |||
|
30 | ||||
37 | #-------------------------------------------------------------------------- |
|
31 | #-------------------------------------------------------------------------- | |
38 | # Kernel management methods |
|
32 | # Kernel management methods | |
39 | #-------------------------------------------------------------------------- |
|
33 | #-------------------------------------------------------------------------- | |
40 |
|
34 | |||
41 | def start_kernel(self, **kwds): |
|
35 | def start_kernel(self, **kwds): | |
42 | from IPython.kernel.inprocess.ipkernel import InProcessKernel |
|
36 | from IPython.kernel.inprocess.ipkernel import InProcessKernel | |
43 | self.kernel = InProcessKernel() |
|
37 | self.kernel = InProcessKernel(parent=self, session=self.session) | |
44 |
|
38 | |||
45 | def shutdown_kernel(self): |
|
39 | def shutdown_kernel(self): | |
46 | self._kill_kernel() |
|
40 | self._kill_kernel() |
@@ -25,7 +25,7 b' class InProcessKernelTestCase(unittest.TestCase):' | |||||
25 | def setUp(self): |
|
25 | def setUp(self): | |
26 | self.km = InProcessKernelManager() |
|
26 | self.km = InProcessKernelManager() | |
27 | self.km.start_kernel() |
|
27 | self.km.start_kernel() | |
28 | self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel) |
|
28 | self.kc = self.km.client() | |
29 | self.kc.start_channels() |
|
29 | self.kc.start_channels() | |
30 | self.kc.wait_for_ready() |
|
30 | self.kc.wait_for_ready() | |
31 |
|
31 | |||
@@ -61,7 +61,7 b' class InProcessKernelTestCase(unittest.TestCase):' | |||||
61 | kernel.shell.run_cell('print("foo")') |
|
61 | kernel.shell.run_cell('print("foo")') | |
62 | self.assertEqual(io.stdout, 'foo\n') |
|
62 | self.assertEqual(io.stdout, 'foo\n') | |
63 |
|
63 | |||
64 | kc = BlockingInProcessKernelClient(kernel=kernel) |
|
64 | kc = BlockingInProcessKernelClient(kernel=kernel, session=kernel.session) | |
65 | kernel.frontends.append(kc) |
|
65 | kernel.frontends.append(kc) | |
66 | kc.execute('print("bar")') |
|
66 | kc.execute('print("bar")') | |
67 | out, err = assemble_output(kc.iopub_channel) |
|
67 | out, err = assemble_output(kc.iopub_channel) |
@@ -24,7 +24,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
24 | self.assert_(km.has_kernel) |
|
24 | self.assert_(km.has_kernel) | |
25 | self.assert_(km.kernel is not None) |
|
25 | self.assert_(km.kernel is not None) | |
26 |
|
26 | |||
27 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
27 | kc = km.client() | |
28 | self.assert_(not kc.channels_running) |
|
28 | self.assert_(not kc.channels_running) | |
29 |
|
29 | |||
30 | kc.start_channels() |
|
30 | kc.start_channels() | |
@@ -49,7 +49,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
49 | """ |
|
49 | """ | |
50 | km = InProcessKernelManager() |
|
50 | km = InProcessKernelManager() | |
51 | km.start_kernel() |
|
51 | km.start_kernel() | |
52 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
52 | kc = km.client() | |
53 | kc.start_channels() |
|
53 | kc.start_channels() | |
54 | kc.wait_for_ready() |
|
54 | kc.wait_for_ready() | |
55 | kc.execute('foo = 1') |
|
55 | kc.execute('foo = 1') | |
@@ -60,7 +60,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
60 | """ |
|
60 | """ | |
61 | km = InProcessKernelManager() |
|
61 | km = InProcessKernelManager() | |
62 | km.start_kernel() |
|
62 | km.start_kernel() | |
63 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
63 | kc = km.client() | |
64 | kc.start_channels() |
|
64 | kc.start_channels() | |
65 | kc.wait_for_ready() |
|
65 | kc.wait_for_ready() | |
66 | km.kernel.shell.push({'my_bar': 0, 'my_baz': 1}) |
|
66 | km.kernel.shell.push({'my_bar': 0, 'my_baz': 1}) | |
@@ -75,7 +75,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
75 | """ |
|
75 | """ | |
76 | km = InProcessKernelManager() |
|
76 | km = InProcessKernelManager() | |
77 | km.start_kernel() |
|
77 | km.start_kernel() | |
78 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
78 | kc = km.client() | |
79 | kc.start_channels() |
|
79 | kc.start_channels() | |
80 | kc.wait_for_ready() |
|
80 | kc.wait_for_ready() | |
81 | km.kernel.shell.user_ns['foo'] = 1 |
|
81 | km.kernel.shell.user_ns['foo'] = 1 | |
@@ -92,7 +92,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):' | |||||
92 | """ |
|
92 | """ | |
93 | km = InProcessKernelManager() |
|
93 | km = InProcessKernelManager() | |
94 | km.start_kernel() |
|
94 | km.start_kernel() | |
95 | kc = BlockingInProcessKernelClient(kernel=km.kernel) |
|
95 | kc = km.client() | |
96 | kc.start_channels() |
|
96 | kc.start_channels() | |
97 | kc.wait_for_ready() |
|
97 | kc.wait_for_ready() | |
98 | kc.execute('%who') |
|
98 | kc.execute('%who') |
General Comments 0
You need to be logged in to leave comments.
Login now