MCPcopy Create free account
hub / github.com/ipython/ipython / kill_embedded

Method kill_embedded

IPython/terminal/embed.py:40–93  ·  view source on GitHub ↗

%kill_embedded : deactivate for good the current embedded IPython This function (after asking for confirmation) sets an internal flag so that an embedded IPython will never activate again for the given call location. This is useful to permanently disable a shell that is bein

(self, parameter_s='')

Source from the content-addressed store, hash-verified

38 @magic_arguments.argument('-y', '--yes', action='store_true',
39 help='Do not ask confirmation')
40 def kill_embedded(self, parameter_s=''):
41 """%kill_embedded : deactivate for good the current embedded IPython
42
43 This function (after asking for confirmation) sets an internal flag so
44 that an embedded IPython will never activate again for the given call
45 location. This is useful to permanently disable a shell that is being
46 called inside a loop: once you've figured out what you needed from it,
47 you may then kill it and the program will then continue to run without
48 the interactive shell interfering again.
49
50
51 Kill Instance Option:
52
53 If for some reasons you need to kill the location where the instance
54 is created and not called, for example if you create a single
55 instance in one place and debug in many locations, you can use the
56 ``--instance`` option to kill this specific instance. Like for the
57 ``call location`` killing an "instance" should work even if it is
58 recreated within a loop.
59
60 .. note::
61
62 This was the default behavior before IPython 5.2
63
64 """
65
66 args = magic_arguments.parse_argstring(self.kill_embedded, parameter_s)
67 print(args)
68 if args.instance:
69 # let no ask
70 if not args.yes:
71 kill = ask_yes_no(
72 "Are you sure you want to kill this embedded instance? [y/N] ", 'n')
73 else:
74 kill = True
75 if kill:
76 self.shell._disable_init_location()
77 print("This embedded IPython instance will not reactivate anymore "
78 "once you exit.")
79 else:
80 if not args.yes:
81 kill = ask_yes_no(
82 "Are you sure you want to kill this embedded call_location? [y/N] ", 'n')
83 else:
84 kill = True
85 if kill:
86 self.shell.embedded_active = False
87 print("This embedded IPython call location will not reactivate anymore "
88 "once you exit.")
89
90 if args.exit:
91 # Ask-exit does not really ask, it just set internals flags to exit
92 # on next loop.
93 self.shell.ask_exit()
94
95
96 @line_magic

Callers

nothing calls this directly

Calls 4

ask_yes_noFunction · 0.90
parse_argstringMethod · 0.80
ask_exitMethod · 0.80

Tested by

no test coverage detected