Show More
@@ -39,8 +39,7 b' class EmbeddedMagics(Magics):' | |||||
39 | interfering again. |
|
39 | interfering again. | |
40 | """ |
|
40 | """ | |
41 |
|
41 | |||
42 | kill = ask_yes_no("Are you sure you want to kill this embedded instance " |
|
42 | kill = ask_yes_no("Are you sure you want to kill this embedded instance? [y/N] ",'n') | |
43 | "(y/n)? [y/N] ",'n') |
|
|||
44 | if kill: |
|
43 | if kill: | |
45 | self.shell.embedded_active = False |
|
44 | self.shell.embedded_active = False | |
46 | print ("This embedded IPython will not reactivate anymore " |
|
45 | print ("This embedded IPython will not reactivate anymore " | |
@@ -66,13 +65,25 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
66 | dummy_mode = Bool(False) |
|
65 | dummy_mode = Bool(False) | |
67 | exit_msg = Unicode('') |
|
66 | exit_msg = Unicode('') | |
68 | embedded = CBool(True) |
|
67 | embedded = CBool(True) | |
69 | embedded_active = CBool(True) |
|
|||
70 | should_raise = CBool(False) |
|
68 | should_raise = CBool(False) | |
71 | # Like the base class display_banner is not configurable, but here it |
|
69 | # Like the base class display_banner is not configurable, but here it | |
72 | # is True by default. |
|
70 | # is True by default. | |
73 | display_banner = CBool(True) |
|
71 | display_banner = CBool(True) | |
74 | exit_msg = Unicode() |
|
72 | exit_msg = Unicode() | |
75 |
|
73 | |||
|
74 | _inactive_locations = set() | |||
|
75 | ||||
|
76 | @property | |||
|
77 | def embedded_active(self): | |||
|
78 | return self._call_location_id not in InteractiveShellEmbed._inactive_locations | |||
|
79 | ||||
|
80 | @embedded_active.setter | |||
|
81 | def embedded_active(self, value): | |||
|
82 | if value : | |||
|
83 | if self._call_location_id in InteractiveShellEmbed._inactive_locations: | |||
|
84 | InteractiveShellEmbed._inactive_locations.remove(self._call_location_id) | |||
|
85 | else: | |||
|
86 | InteractiveShellEmbed._inactive_locations.add(self._call_location_id) | |||
76 |
|
87 | |||
77 | def __init__(self, **kw): |
|
88 | def __init__(self, **kw): | |
78 |
|
89 | |||
@@ -81,8 +92,13 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
81 | warnings.warn("user_global_ns has been replaced by user_module. The\ |
|
92 | warnings.warn("user_global_ns has been replaced by user_module. The\ | |
82 | parameter will be ignored, and removed in IPython 5.0", DeprecationWarning) |
|
93 | parameter will be ignored, and removed in IPython 5.0", DeprecationWarning) | |
83 |
|
94 | |||
|
95 | self._call_location_id = kw.pop('_call_location_id', None) | |||
|
96 | ||||
84 | super(InteractiveShellEmbed,self).__init__(**kw) |
|
97 | super(InteractiveShellEmbed,self).__init__(**kw) | |
85 |
|
98 | |||
|
99 | if not self._call_location_id: | |||
|
100 | frame = sys._getframe(1) | |||
|
101 | self._call_location_id = '%s:%s' % (frame.f_code.co_filename, frame.f_lineno) | |||
86 | # don't use the ipython crash handler so that user exceptions aren't |
|
102 | # don't use the ipython crash handler so that user exceptions aren't | |
87 | # trapped |
|
103 | # trapped | |
88 | sys.excepthook = ultratb.FormattedTB(color_scheme=self.colors, |
|
104 | sys.excepthook = ultratb.FormattedTB(color_scheme=self.colors, | |
@@ -298,7 +314,8 b' def embed(**kwargs):' | |||||
298 | if saved_shell_instance is not None: |
|
314 | if saved_shell_instance is not None: | |
299 | cls = type(saved_shell_instance) |
|
315 | cls = type(saved_shell_instance) | |
300 | cls.clear_instance() |
|
316 | cls.clear_instance() | |
301 | shell = InteractiveShellEmbed.instance(**kwargs) |
|
317 | frame = sys._getframe(1) | |
|
318 | shell = InteractiveShellEmbed.instance(_call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno), **kwargs) | |||
302 | shell(header=header, stack_depth=2, compile_flags=compile_flags) |
|
319 | shell(header=header, stack_depth=2, compile_flags=compile_flags) | |
303 | InteractiveShellEmbed.clear_instance() |
|
320 | InteractiveShellEmbed.clear_instance() | |
304 | #restore previous instance |
|
321 | #restore previous instance |
General Comments 0
You need to be logged in to leave comments.
Login now