##// END OF EJS Templates
- Fix a bug introduced by r1357 which broke embedding....
fperez -
Show More
@@ -4,7 +4,7 b''
4 4 All the matplotlib support code was co-developed with John Hunter,
5 5 matplotlib's author.
6 6
7 $Id: Shell.py 2222 2007-04-06 17:11:27Z fperez $"""
7 $Id: Shell.py 2577 2007-08-02 23:50:02Z fperez $"""
8 8
9 9 #*****************************************************************************
10 10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -39,8 +39,8 b' except ImportError:'
39 39
40 40 # IPython imports
41 41 import IPython
42 from IPython import ultraTB
43 from IPython.genutils import Term,warn,error,flag_calls
42 from IPython import ultraTB, ipapi
43 from IPython.genutils import Term,warn,error,flag_calls, ask_yes_no
44 44 from IPython.iplib import InteractiveShell
45 45 from IPython.ipmaker import make_IPython
46 46 from IPython.Magic import Magic
@@ -79,6 +79,22 b' class IPShell:'
79 79 sys.exit()
80 80
81 81 #-----------------------------------------------------------------------------
82 def kill_embedded(self,parameter_s=''):
83 """%kill_embedded : deactivate for good the current embedded IPython.
84
85 This function (after asking for confirmation) sets an internal flag so that
86 an embedded IPython will never activate again. This is useful to
87 permanently disable a shell that is being called inside a loop: once you've
88 figured out what you needed from it, you may then kill it and the program
89 will then continue to run without the interactive shell interfering again.
90 """
91
92 kill = ask_yes_no("Are you sure you want to kill this embedded instance "
93 "(y/n)? [y/N] ",'n')
94 if kill:
95 self.shell.embedded_active = False
96 print "This embedded IPython will not reactivate anymore once you exit."
97
82 98 class IPShellEmbed:
83 99 """Allow embedding an IPython shell into a running program.
84 100
@@ -153,6 +169,9 b' class IPShellEmbed:'
153 169 embedded=True,
154 170 user_ns=user_ns)
155 171
172 ip = ipapi.IPApi(self.IP)
173 ip.expose_magic("kill_embedded",kill_embedded)
174
156 175 # copy our own displayhook also
157 176 self.sys_displayhook_embed = sys.displayhook
158 177 # and leave the system's display hook clean
@@ -196,6 +215,14 b' class IPShellEmbed:'
196 215 The optional keyword parameter dummy controls whether the call
197 216 actually does anything. """
198 217
218 # If the user has turned it off, go away
219 if not self.IP.embedded_active:
220 return
221
222 # Normal exits from interactive mode set this flag, so the shell can't
223 # re-enter (it checks this variable at the start of interactive mode).
224 self.IP.exit_now = False
225
199 226 # Allow the dummy parameter to override the global __dummy_mode
200 227 if dummy or (dummy != 0 and self.__dummy_mode):
201 228 return
@@ -5,7 +5,7 b' General purpose utilities.'
5 5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 6 these things are also convenient when working at the command line.
7 7
8 $Id: genutils.py 2568 2007-07-29 21:38:44Z fperez $"""
8 $Id: genutils.py 2577 2007-08-02 23:50:02Z fperez $"""
9 9
10 10 #*****************************************************************************
11 11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -1055,7 +1055,7 b" def raw_input_ext(prompt='', ps2='... '):"
1055 1055
1056 1056 #----------------------------------------------------------------------------
1057 1057 def ask_yes_no(prompt,default=None):
1058 """Asks a question and returns an integer 1/0 (y/n) answer.
1058 """Asks a question and returns a boolean (y/n) answer.
1059 1059
1060 1060 If default is given (one of 'y','n'), it is used if the user input is
1061 1061 empty. Otherwise the question is repeated until an answer is given.
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 2571 2007-08-01 14:48:03Z vivainio $
9 $Id: iplib.py 2577 2007-08-02 23:50:02Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -228,6 +228,10 b' class InteractiveShell(object,Magic):'
228 228 # We need to know whether the instance is meant for embedding, since
229 229 # global/local namespaces need to be handled differently in that case
230 230 self.embedded = embedded
231 if embedded:
232 # Control variable so users can, from within the embedded instance,
233 # permanently deactivate it.
234 self.embedded_active = True
231 235
232 236 # command compiler
233 237 self.compile = codeop.CommandCompiler()
@@ -1566,7 +1570,7 b' want to merge them back into the new files.""" % locals()'
1566 1570 # all names in the builtin namespace needed by ipython point to
1567 1571 # ourselves, and not to other instances.
1568 1572 self.add_builtins()
1569
1573
1570 1574 self.interact(header)
1571 1575
1572 1576 # now, purge out the user namespace from anything we might have added
@@ -1,3 +1,17 b''
1 2007-08-02 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/Shell.py (IPShellEmbed.__call__): fix bug introduced in
4 r1357, which had killed multiple invocations of an embedded
5 ipython (this means that example-embed has been broken for over 1
6 year!!!). Rather than possibly breaking the batch stuff for which
7 the code in iplib.py/interact was introduced, I worked around the
8 problem in the embedding class in Shell.py. We really need a
9 bloody test suite for this code, I'm sick of finding stuff that
10 used to work breaking left and right every time I use an old
11 feature I hadn't touched in a few months.
12 (kill_embedded): Add a new magic that only shows up in embedded
13 mode, to allow users to permanently deactivate an embedded instance.
14
1 15 2007-08-01 Ville Vainio <vivainio@gmail.com>
2 16
3 17 * iplib.py, ipy_profile_sh.py (runlines): Fix the bug where raw
@@ -54,7 +54,9 b" print '\\nHello. This is printed from the main controller program.\\n'"
54 54 # You can then call ipshell() anywhere you need it (with an optional
55 55 # message):
56 56 ipshell('***Called from top level. '
57 'Hit Ctrl-D to exit interpreter and continue program.')
57 'Hit Ctrl-D to exit interpreter and continue program.\n'
58 'Note that if you use %kill_embedded, you can fully deactivate\n'
59 'This embedded instance so it will never turn on again')
58 60
59 61 print '\nBack in caller program, moving along...\n'
60 62
General Comments 0
You need to be logged in to leave comments. Login now