##// END OF EJS Templates
improve cleanup of connection files...
improve cleanup of connection files * allow clean shutdown of qtconsole on sigint * init_kernel_manager registers cleanup_connection_file with atexit * connection_file trait is guaranteed to be abspath at end of init_connection_file(), so find methods are no longer necessary after this call. * move cf removal from KM.__del__ to KM.cleanup_connection_file * _new_connection_file only uses last segment of uuid, not the whole thing, which is ugly and overkill 2**48 is enough kernels.

File last commit:

r5608:31d0eac8
r5609:b8f41d55
Show More
app.py
124 lines | 3.9 KiB | text/x-python | PythonLexer
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 """ A minimal application using the ZMQ-based terminal IPython frontend.
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 This is not a complete console app, as subprocess will not be able to receive
input, there is no real readline support, among other limitations.
Authors:
* Min RK
* Paul Ivanov
"""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 import signal
import sys
import time
from IPython.frontend.terminal.ipapp import TerminalIPythonApp
from IPython.utils.traitlets import (
Dict, List, Unicode, Int, CaselessStrEnum, CBool, Any
)
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 from IPython.zmq.ipkernel import IPKernelApp
from IPython.zmq.session import Session, default_secure
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 from IPython.zmq.zmqshell import ZMQInteractiveShell
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 from IPython.frontend.kernelmixinapp import (
IPythonMixinConsoleApp, app_aliases, app_flags
)
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 from IPython.frontend.zmqterminal.interactiveshell import ZMQTerminalInteractiveShell
#-----------------------------------------------------------------------------
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 # Globals
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 #-----------------------------------------------------------------------------
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 _examples = """
ipython console # start the ZMQ-based console
Paul Ivanov
documentation update
r5607 ipython console --existing # connect to an existing ipython session
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 """
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600
#-----------------------------------------------------------------------------
# Flags and Aliases
#-----------------------------------------------------------------------------
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 # XXX: the app_flags should really be flags from the mixin
flags = dict(app_flags)
frontend_flags = { }
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 flags.update(frontend_flags)
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 frontend_flags = frontend_flags.keys()
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 aliases = dict(app_aliases)
frontend_aliases = dict()
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600
aliases.update(frontend_aliases)
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 class ZMQTerminalIPythonApp(TerminalIPythonApp, IPythonMixinConsoleApp):
Paul Ivanov
documentation update
r5607 name = "ipython console"
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 """Start a terminal frontend to the IPython zmq kernel."""
Paul Ivanov
documentation update
r5607
description = """
The IPython terminal-based Console.
This launches a Console application inside a terminal.
The Console supports various extra features beyond the traditional
single-process Terminal IPython shell, such as connecting to an
existing ipython session, via:
ipython console --existing
where the previous session could have been created by another ipython
console, an ipython qtconsole, or by opening an ipython notebook.
"""
examples = _examples
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 classes = List([IPKernelApp, ZMQTerminalInteractiveShell])
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 flags = Dict(flags)
aliases = Dict(aliases)
Paul Ivanov
documentation update
r5607 subcommands = Dict()
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 def parse_command_line(self, argv=None):
super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 IPythonMixinConsoleApp.parse_command_line(self,argv)
self.swallow_args(frontend_aliases,frontend_flags,argv=argv)
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600
def init_shell(self):
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604 IPythonMixinConsoleApp.initialize(self)
Paul Ivanov
restore KeyboardInterrupt capability
r5605 # relay sigint to kernel
signal.signal(signal.SIGINT, self.handle_sigint)
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 self.shell = ZMQTerminalInteractiveShell.instance(config=self.config,
display_banner=False, profile_dir=self.profile_dir,
ipython_dir=self.ipython_dir, kernel_manager=self.kernel_manager)
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 def handle_sigint(self, *args):
self.shell.write('KeyboardInterrupt\n')
Paul Ivanov
report inability to signal --existing kernels
r5608 if self.kernel_manager.has_kernel:
self.kernel_manager.interrupt_kernel()
else:
print 'Kernel process is either remote or unspecified.',
print 'Cannot interrupt.'
Paul Ivanov
zmqterminal now uses the zmq mixin app
r5604
MinRK
zmqterminal subclasses TerminalInteractiveShell/IPApp...
r5600 def init_code(self):
# no-op in the frontend, code gets run in the backend
pass
def launch_new_instance():
"""Create and run a full blown IPython instance"""
app = ZMQTerminalIPythonApp.instance()
app.initialize()
app.start()
if __name__ == '__main__':
launch_new_instance()