Show More
@@ -46,41 +46,19 b' class EmbeddedMagics(Magics):' | |||||
46 | print ("This embedded IPython will not reactivate anymore " |
|
46 | print ("This embedded IPython will not reactivate anymore " | |
47 | "once you exit.") |
|
47 | "once you exit.") | |
48 |
|
48 | |||
49 | if sys.version_info > (3,): |
|
|||
50 |
|
49 | |||
51 |
|
|
50 | @line_magic | |
52 |
|
|
51 | def exit_raise(self, parameter_s=''): | |
53 |
|
|
52 | """%exit_raise Make the current embedded kernel exit and raise and exception. | |
54 |
|
||||
55 | You can change that again during current session by calling `%raise_on_exit` with `True`/`False` as parameter |
|
|||
56 |
|
53 | |||
57 |
|
|
54 | This function (after asking for confirmation) sets an internal flag so | |
58 |
|
|
55 | that an embedded IPython will raise a `KillEmbeded` Exception on exit. | |
59 |
permanently exit a loop that create IPython embed |
|
56 | This is useful to permanently exit a loop that create IPython embed | |
60 |
|
57 | instance. | ||
61 | Available only for Python 3. |
|
|||
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.") |
|
61 | self.shell.ask_exit() | |
81 | else : |
|
|||
82 | self.shell.should_raise = False |
|
|||
83 | print ("This embedded IPython will not raise while exiting.") |
|
|||
84 |
|
62 | |||
85 |
|
63 | |||
86 |
|
64 |
General Comments 0
You need to be logged in to leave comments.
Login now