##// END OF EJS Templates
report inability to signal --existing kernels
Paul Ivanov -
Show More
@@ -1,120 +1,124 b''
1 1 """ A minimal application using the ZMQ-based terminal IPython frontend.
2 2
3 3 This is not a complete console app, as subprocess will not be able to receive
4 4 input, there is no real readline support, among other limitations.
5 5
6 6 Authors:
7 7
8 8 * Min RK
9 9 * Paul Ivanov
10 10
11 11 """
12 12
13 13 #-----------------------------------------------------------------------------
14 14 # Imports
15 15 #-----------------------------------------------------------------------------
16 16 import signal
17 17 import sys
18 18 import time
19 19
20 20 from IPython.frontend.terminal.ipapp import TerminalIPythonApp
21 21
22 22 from IPython.utils.traitlets import (
23 23 Dict, List, Unicode, Int, CaselessStrEnum, CBool, Any
24 24 )
25 25 from IPython.zmq.ipkernel import IPKernelApp
26 26 from IPython.zmq.session import Session, default_secure
27 27 from IPython.zmq.zmqshell import ZMQInteractiveShell
28 28 from IPython.frontend.kernelmixinapp import (
29 29 IPythonMixinConsoleApp, app_aliases, app_flags
30 30 )
31 31
32 32 from IPython.frontend.zmqterminal.interactiveshell import ZMQTerminalInteractiveShell
33 33
34 34 #-----------------------------------------------------------------------------
35 35 # Globals
36 36 #-----------------------------------------------------------------------------
37 37
38 38 _examples = """
39 39 ipython console # start the ZMQ-based console
40 40 ipython console --existing # connect to an existing ipython session
41 41 """
42 42
43 43 #-----------------------------------------------------------------------------
44 44 # Flags and Aliases
45 45 #-----------------------------------------------------------------------------
46 46
47 47 # XXX: the app_flags should really be flags from the mixin
48 48 flags = dict(app_flags)
49 49 frontend_flags = { }
50 50 flags.update(frontend_flags)
51 51
52 52 frontend_flags = frontend_flags.keys()
53 53
54 54 aliases = dict(app_aliases)
55 55
56 56 frontend_aliases = dict()
57 57
58 58 aliases.update(frontend_aliases)
59 59
60 60 #-----------------------------------------------------------------------------
61 61 # Classes
62 62 #-----------------------------------------------------------------------------
63 63
64 64
65 65 class ZMQTerminalIPythonApp(TerminalIPythonApp, IPythonMixinConsoleApp):
66 66 name = "ipython console"
67 67 """Start a terminal frontend to the IPython zmq kernel."""
68 68
69 69 description = """
70 70 The IPython terminal-based Console.
71 71
72 72 This launches a Console application inside a terminal.
73 73
74 74 The Console supports various extra features beyond the traditional
75 75 single-process Terminal IPython shell, such as connecting to an
76 76 existing ipython session, via:
77 77
78 78 ipython console --existing
79 79
80 80 where the previous session could have been created by another ipython
81 81 console, an ipython qtconsole, or by opening an ipython notebook.
82 82
83 83 """
84 84 examples = _examples
85 85
86 86 classes = List([IPKernelApp, ZMQTerminalInteractiveShell])
87 87 flags = Dict(flags)
88 88 aliases = Dict(aliases)
89 89 subcommands = Dict()
90 90 def parse_command_line(self, argv=None):
91 91 super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
92 92 IPythonMixinConsoleApp.parse_command_line(self,argv)
93 93 self.swallow_args(frontend_aliases,frontend_flags,argv=argv)
94 94
95 95 def init_shell(self):
96 96 IPythonMixinConsoleApp.initialize(self)
97 97 # relay sigint to kernel
98 98 signal.signal(signal.SIGINT, self.handle_sigint)
99 99 self.shell = ZMQTerminalInteractiveShell.instance(config=self.config,
100 100 display_banner=False, profile_dir=self.profile_dir,
101 101 ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager)
102 102
103 103 def handle_sigint(self, *args):
104 104 self.shell.write('KeyboardInterrupt\n')
105 self.kernel_manager.interrupt_kernel()
105 if self.kernel_manager.has_kernel:
106 self.kernel_manager.interrupt_kernel()
107 else:
108 print 'Kernel process is either remote or unspecified.',
109 print 'Cannot interrupt.'
106 110
107 111 def init_code(self):
108 112 # no-op in the frontend, code gets run in the backend
109 113 pass
110 114
111 115 def launch_new_instance():
112 116 """Create and run a full blown IPython instance"""
113 117 app = ZMQTerminalIPythonApp.instance()
114 118 app.initialize()
115 119 app.start()
116 120
117 121
118 122 if __name__ == '__main__':
119 123 launch_new_instance()
120 124
General Comments 0
You need to be logged in to leave comments. Login now