Show More
@@ -23,16 +23,13 b' Notes' | |||
|
23 | 23 | #----------------------------------------------------------------------------- |
|
24 | 24 | |
|
25 | 25 | from __future__ import with_statement |
|
26 | import __main__ | |
|
27 | 26 | |
|
28 | 27 | import sys |
|
29 | try: | |
|
30 | from contextlib import nested | |
|
31 | except: | |
|
32 | from IPython.utils.nested_context import nested | |
|
28 | from contextlib import nested | |
|
33 | 29 | import warnings |
|
34 | 30 | |
|
35 | 31 | from IPython.core import ultratb |
|
32 | from IPython.core.magic import Magics, register_magics, line_magic | |
|
36 | 33 | from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell |
|
37 | 34 | from IPython.frontend.terminal.ipapp import load_default_config |
|
38 | 35 | |
@@ -45,21 +42,27 b' from IPython.utils.io import ask_yes_no' | |||
|
45 | 42 | #----------------------------------------------------------------------------- |
|
46 | 43 | |
|
47 | 44 | # This is an additional magic that is exposed in embedded shells. |
|
48 | def kill_embedded(self,parameter_s=''): | |
|
49 | """%kill_embedded : deactivate for good the current embedded IPython. | |
|
50 | ||
|
51 | This function (after asking for confirmation) sets an internal flag so that | |
|
52 | an embedded IPython will never activate again. This is useful to | |
|
53 | permanently disable a shell that is being called inside a loop: once you've | |
|
54 | figured out what you needed from it, you may then kill it and the program | |
|
55 | will then continue to run without the interactive shell interfering again. | |
|
56 | """ | |
|
45 | @register_magics | |
|
46 | class EmbeddedMagics(Magics): | |
|
47 | ||
|
48 | @line_magic | |
|
49 | def kill_embedded(self, parameter_s=''): | |
|
50 | """%kill_embedded : deactivate for good the current embedded IPython. | |
|
51 | ||
|
52 | This function (after asking for confirmation) sets an internal flag so | |
|
53 | that an embedded IPython will never activate again. This is useful to | |
|
54 | permanently disable a shell that is being called inside a loop: once | |
|
55 | you've figured out what you needed from it, you may then kill it and | |
|
56 | the program will then continue to run without the interactive shell | |
|
57 | interfering again. | |
|
58 | """ | |
|
57 | 59 | |
|
58 | kill = ask_yes_no("Are you sure you want to kill this embedded instance " | |
|
59 | "(y/n)? [y/N] ",'n') | |
|
60 | if kill: | |
|
61 | self.embedded_active = False | |
|
62 |
print "This embedded IPython will not reactivate anymore |
|
|
60 | kill = ask_yes_no("Are you sure you want to kill this embedded instance " | |
|
61 | "(y/n)? [y/N] ",'n') | |
|
62 | if kill: | |
|
63 | self.shell.embedded_active = False | |
|
64 | print ("This embedded IPython will not reactivate anymore " | |
|
65 | "once you exit.") | |
|
63 | 66 | |
|
64 | 67 | |
|
65 | 68 | class InteractiveShellEmbed(TerminalInteractiveShell): |
@@ -89,7 +92,6 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||
|
89 | 92 | ) |
|
90 | 93 | |
|
91 | 94 | self.exit_msg = exit_msg |
|
92 | self.define_magic("kill_embedded", kill_embedded) | |
|
93 | 95 | |
|
94 | 96 | # don't use the ipython crash handler so that user exceptions aren't |
|
95 | 97 | # trapped |
@@ -100,6 +102,10 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||
|
100 | 102 | def init_sys_modules(self): |
|
101 | 103 | pass |
|
102 | 104 | |
|
105 | def init_magics(self): | |
|
106 | super(InteractiveShellEmbed, self).init_magics() | |
|
107 | self.register_magics(EmbeddedMagics) | |
|
108 | ||
|
103 | 109 | def __call__(self, header='', local_ns=None, module=None, dummy=None, |
|
104 | 110 | stack_depth=1, global_ns=None): |
|
105 | 111 | """Activate the interactive interpreter. |
General Comments 0
You need to be logged in to leave comments.
Login now