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