Show More
@@ -0,0 +1,46 b'' | |||||
|
1 | import os | |||
|
2 | ||||
|
3 | from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget | |||
|
4 | from IPython.frontend.qt.inprocess import QtInProcessKernelClient | |||
|
5 | from IPython.kernel.inprocess import InProcessKernelManager | |||
|
6 | from IPython.lib import guisupport | |||
|
7 | ||||
|
8 | ||||
|
9 | def print_process_id(): | |||
|
10 | print 'Process ID is:', os.getpid() | |||
|
11 | ||||
|
12 | ||||
|
13 | def main(): | |||
|
14 | # Print the ID of the main process | |||
|
15 | print_process_id() | |||
|
16 | ||||
|
17 | app = guisupport.get_app_qt4() | |||
|
18 | ||||
|
19 | # Create an in-process kernel | |||
|
20 | # >>> print_process_id() | |||
|
21 | # will print the same process ID as the main process | |||
|
22 | kernel_manager = InProcessKernelManager() | |||
|
23 | kernel_manager.start_kernel() | |||
|
24 | kernel = kernel_manager.kernel | |||
|
25 | kernel.gui = 'qt4' | |||
|
26 | kernel.shell.push({'foo': 43, 'print_process_id': print_process_id}) | |||
|
27 | ||||
|
28 | kernel_client = QtInProcessKernelClient(kernel=kernel) | |||
|
29 | kernel_client.start_channels() | |||
|
30 | ||||
|
31 | def stop(): | |||
|
32 | kernel_client.stop_channels() | |||
|
33 | kernel_manager.shutdown_kernel() | |||
|
34 | app.exit() | |||
|
35 | ||||
|
36 | control = RichIPythonWidget() | |||
|
37 | control.kernel_manager = kernel_manager | |||
|
38 | control.kernel_client = kernel_client | |||
|
39 | control.exit_requested.connect(stop) | |||
|
40 | control.show() | |||
|
41 | ||||
|
42 | guisupport.start_event_loop_qt4(app) | |||
|
43 | ||||
|
44 | ||||
|
45 | if __name__ == '__main__': | |||
|
46 | main() |
@@ -0,0 +1,30 b'' | |||||
|
1 | import os | |||
|
2 | ||||
|
3 | from IPython.kernel.inprocess import InProcessKernelManager | |||
|
4 | from IPython.frontend.terminal.console.interactiveshell import ZMQTerminalInteractiveShell | |||
|
5 | ||||
|
6 | ||||
|
7 | def print_process_id(): | |||
|
8 | print 'Process ID is:', os.getpid() | |||
|
9 | ||||
|
10 | ||||
|
11 | def main(): | |||
|
12 | print_process_id() | |||
|
13 | ||||
|
14 | # Create an in-process kernel | |||
|
15 | # >>> print_process_id() | |||
|
16 | # will print the same process ID as the main process | |||
|
17 | kernel_manager = InProcessKernelManager() | |||
|
18 | kernel_manager.start_kernel() | |||
|
19 | kernel = kernel_manager.kernel | |||
|
20 | kernel.gui = 'qt4' | |||
|
21 | kernel.shell.push({'foo': 43, 'print_process_id': print_process_id}) | |||
|
22 | client = kernel_manager.client() | |||
|
23 | client.start_channels() | |||
|
24 | ||||
|
25 | shell = ZMQTerminalInteractiveShell(kernel_manager=kernel_manager, kernel_client=client) | |||
|
26 | shell.mainloop() | |||
|
27 | ||||
|
28 | ||||
|
29 | if __name__ == '__main__': | |||
|
30 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now