##// END OF EJS Templates
restore KeyboardInterrupt capability
Paul Ivanov -
Show More
@@ -1,100 +1,101 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 --pylab # start with pylab plotting mode
40 ipython console --pylab # start with pylab plotting mode
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 """Start a terminal frontend to the IPython zmq kernel."""
66 """Start a terminal frontend to the IPython zmq kernel."""
67
67
68 classes = List([IPKernelApp, ZMQTerminalInteractiveShell])
68 classes = List([IPKernelApp, ZMQTerminalInteractiveShell])
69 flags = Dict(flags)
69 flags = Dict(flags)
70 aliases = Dict(aliases)
70 aliases = Dict(aliases)
71 def parse_command_line(self, argv=None):
71 def parse_command_line(self, argv=None):
72 super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
72 super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
73 IPythonMixinConsoleApp.parse_command_line(self,argv)
73 IPythonMixinConsoleApp.parse_command_line(self,argv)
74 self.swallow_args(frontend_aliases,frontend_flags,argv=argv)
74 self.swallow_args(frontend_aliases,frontend_flags,argv=argv)
75
75
76 def init_shell(self):
76 def init_shell(self):
77 IPythonMixinConsoleApp.initialize(self)
77 IPythonMixinConsoleApp.initialize(self)
78 #self.init_kernel_manager()
78 # relay sigint to kernel
79 signal.signal(signal.SIGINT, self.handle_sigint)
79 self.shell = ZMQTerminalInteractiveShell.instance(config=self.config,
80 self.shell = ZMQTerminalInteractiveShell.instance(config=self.config,
80 display_banner=False, profile_dir=self.profile_dir,
81 display_banner=False, profile_dir=self.profile_dir,
81 ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager)
82 ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager)
82
83
83 def handle_sigint(self, *args):
84 def handle_sigint(self, *args):
84 self.shell.write('KeyboardInterrupt\n')
85 self.shell.write('KeyboardInterrupt\n')
85 self.kernel_manager.interrupt_kernel()
86 self.kernel_manager.interrupt_kernel()
86
87
87 def init_code(self):
88 def init_code(self):
88 # no-op in the frontend, code gets run in the backend
89 # no-op in the frontend, code gets run in the backend
89 pass
90 pass
90
91
91 def launch_new_instance():
92 def launch_new_instance():
92 """Create and run a full blown IPython instance"""
93 """Create and run a full blown IPython instance"""
93 app = ZMQTerminalIPythonApp.instance()
94 app = ZMQTerminalIPythonApp.instance()
94 app.initialize()
95 app.initialize()
95 app.start()
96 app.start()
96
97
97
98
98 if __name__ == '__main__':
99 if __name__ == '__main__':
99 launch_new_instance()
100 launch_new_instance()
100
101
General Comments 0
You need to be logged in to leave comments. Login now