##// END OF EJS Templates
Refactor to exit and raise immediately on exit....
Matthias Bussonnier -
Show More
@@ -46,41 +46,19 b' class EmbeddedMagics(Magics):'
46 46 print ("This embedded IPython will not reactivate anymore "
47 47 "once you exit.")
48 48
49 if sys.version_info > (3,):
50 49
51 50 @line_magic
52 def raise_on_exit(self, parameter_s=''):
53 """%raise_on_exit [True|False]: Make the current embeded kernel to raise an exception on exit.
54
55 You can change that again during current session by calling `%raise_on_exit` with `True`/`False` as parameter
51 def exit_raise(self, parameter_s=''):
52 """%exit_raise Make the current embedded kernel exit and raise and exception.
56 53
57 54 This function (after asking for confirmation) sets an internal flag so
58 that an embedded IPython will raise a `KillEmbeded` Exception on exit. This is useful to
59 permanently exit a loop that create IPython embed instance.
60
61 Available only for Python 3.
55 that an embedded IPython will raise a `KillEmbeded` Exception on exit.
56 This is useful to permanently exit a loop that create IPython embed
57 instance.
62 58 """
63 parameter_s = parameter_s.strip().lower()
64
65 should_raise = None
66 if parameter_s in {'yes', 'raise', 'true', '1'}:
67 should_raise = True
68 elif parameter_s in {'no', 'false', '0', 'None'}:
69 should_raise = False
70 else:
71 if self.shell.should_raise :
72 print("The current embed instance will raise on exit, use `%raise_on_exit False` to disable")
73 return
74 else:
75 print("The current embed instance will not raise on exit, use `%raise_on_exit True` to enable")
76 return
77 59
78 if should_raise:
79 60 self.shell.should_raise = True
80 print ("This embedded IPython will raise while exiting.")
81 else :
82 self.shell.should_raise = False
83 print ("This embedded IPython will not raise while exiting.")
61 self.shell.ask_exit()
84 62
85 63
86 64
General Comments 0
You need to be logged in to leave comments. Login now