Show More
@@ -1,34 +1,40 b'' | |||
|
1 | 1 | """ Defines an in-process KernelManager with signals and slots. |
|
2 | 2 | """ |
|
3 | 3 | |
|
4 | 4 | # Local imports. |
|
5 | 5 | from IPython.kernel.inprocess import ( |
|
6 | 6 | InProcessShellChannel, InProcessIOPubChannel, InProcessStdInChannel, |
|
7 | InProcessHBChannel, InProcessKernelClient | |
|
7 | InProcessHBChannel, InProcessKernelClient, InProcessKernelManager, | |
|
8 | 8 | ) |
|
9 | 9 | |
|
10 | 10 | from IPython.utils.traitlets import Type |
|
11 | from kernel_mixins import QtShellChannelMixin, QtIOPubChannelMixin, \ | |
|
12 |
QtS |
|
|
11 | from .kernel_mixins import ( | |
|
12 | QtShellChannelMixin, QtIOPubChannelMixin, | |
|
13 | QtStdInChannelMixin, QtHBChannelMixin, QtKernelClientMixin, | |
|
14 | QtKernelManagerMixin, | |
|
15 | ) | |
|
13 | 16 | |
|
14 | 17 | |
|
15 | 18 | class QtInProcessShellChannel(QtShellChannelMixin, InProcessShellChannel): |
|
16 | 19 | pass |
|
17 | 20 | |
|
18 | 21 | class QtInProcessIOPubChannel(QtIOPubChannelMixin, InProcessIOPubChannel): |
|
19 | 22 | pass |
|
20 | 23 | |
|
21 | 24 | class QtInProcessStdInChannel(QtStdInChannelMixin, InProcessStdInChannel): |
|
22 | 25 | pass |
|
23 | 26 | |
|
24 | 27 | class QtInProcessHBChannel(QtHBChannelMixin, InProcessHBChannel): |
|
25 | 28 | pass |
|
26 | 29 | |
|
27 | 30 | class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient): |
|
28 | 31 | """ An in-process KernelManager with signals and slots. |
|
29 | 32 | """ |
|
30 | 33 | |
|
31 | 34 | iopub_channel_class = Type(QtInProcessIOPubChannel) |
|
32 | 35 | shell_channel_class = Type(QtInProcessShellChannel) |
|
33 | 36 | stdin_channel_class = Type(QtInProcessStdInChannel) |
|
34 | 37 | hb_channel_class = Type(QtInProcessHBChannel) |
|
38 | ||
|
39 | class QtInProcessKernelManager(QtKernelManagerMixin, InProcessKernelManager): | |
|
40 | client_class = __module__ + '.QtInProcessKernelClient' |
@@ -1,46 +1,45 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | |
|
3 | 3 | from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget |
|
4 |
from IPython.frontend.qt.inprocess import QtInProcessKernel |
|
|
5 | from IPython.kernel.inprocess import InProcessKernelManager | |
|
4 | from IPython.frontend.qt.inprocess import QtInProcessKernelManager | |
|
6 | 5 | from IPython.lib import guisupport |
|
7 | 6 | |
|
8 | 7 | |
|
9 | 8 | def print_process_id(): |
|
10 | 9 | print 'Process ID is:', os.getpid() |
|
11 | 10 | |
|
12 | 11 | |
|
13 | 12 | def main(): |
|
14 | 13 | # Print the ID of the main process |
|
15 | 14 | print_process_id() |
|
16 | 15 | |
|
17 | 16 | app = guisupport.get_app_qt4() |
|
18 | 17 | |
|
19 | 18 | # Create an in-process kernel |
|
20 | 19 | # >>> print_process_id() |
|
21 | 20 | # will print the same process ID as the main process |
|
22 | kernel_manager = InProcessKernelManager() | |
|
21 | kernel_manager = QtInProcessKernelManager() | |
|
23 | 22 | kernel_manager.start_kernel() |
|
24 | 23 | kernel = kernel_manager.kernel |
|
25 | 24 | kernel.gui = 'qt4' |
|
26 | 25 | kernel.shell.push({'foo': 43, 'print_process_id': print_process_id}) |
|
27 | 26 | |
|
28 |
kernel_client = |
|
|
27 | kernel_client = kernel_manager.client() | |
|
29 | 28 | kernel_client.start_channels() |
|
30 | 29 | |
|
31 | 30 | def stop(): |
|
32 | 31 | kernel_client.stop_channels() |
|
33 | 32 | kernel_manager.shutdown_kernel() |
|
34 | 33 | app.exit() |
|
35 | 34 | |
|
36 | 35 | control = RichIPythonWidget() |
|
37 | 36 | control.kernel_manager = kernel_manager |
|
38 | 37 | control.kernel_client = kernel_client |
|
39 | 38 | control.exit_requested.connect(stop) |
|
40 | 39 | control.show() |
|
41 | 40 | |
|
42 | 41 | guisupport.start_event_loop_qt4(app) |
|
43 | 42 | |
|
44 | 43 | |
|
45 | 44 | if __name__ == '__main__': |
|
46 | 45 | main() |
@@ -1,30 +1,30 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | |
|
3 | 3 | from IPython.kernel.inprocess import InProcessKernelManager |
|
4 | 4 | from IPython.frontend.terminal.console.interactiveshell import ZMQTerminalInteractiveShell |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | def print_process_id(): |
|
8 | 8 | print 'Process ID is:', os.getpid() |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | def main(): |
|
12 | 12 | print_process_id() |
|
13 | 13 | |
|
14 | 14 | # Create an in-process kernel |
|
15 | 15 | # >>> print_process_id() |
|
16 | 16 | # will print the same process ID as the main process |
|
17 | 17 | kernel_manager = InProcessKernelManager() |
|
18 | 18 | kernel_manager.start_kernel() |
|
19 | 19 | kernel = kernel_manager.kernel |
|
20 | 20 | kernel.gui = 'qt4' |
|
21 | 21 | kernel.shell.push({'foo': 43, 'print_process_id': print_process_id}) |
|
22 | 22 | client = kernel_manager.client() |
|
23 | 23 | client.start_channels() |
|
24 | 24 | |
|
25 |
shell = ZMQTerminalInteractiveShell( |
|
|
25 | shell = ZMQTerminalInteractiveShell(manager=kernel_manager, client=client) | |
|
26 | 26 | shell.mainloop() |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | if __name__ == '__main__': |
|
30 | 30 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now