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,): |
|
49 | ||
50 |
|
50 | @line_magic | ||
51 | @line_magic |
|
51 | def exit_raise(self, parameter_s=''): | |
52 | def raise_on_exit(self, parameter_s=''): |
|
52 | """%exit_raise Make the current embedded kernel exit and raise and exception. | |
53 | """%raise_on_exit [True|False]: Make the current embeded kernel to raise an exception on exit. |
|
53 | ||
54 |
|
54 | This function (after asking for confirmation) sets an internal flag so | ||
55 | You can change that again during current session by calling `%raise_on_exit` with `True`/`False` as parameter |
|
55 | that an embedded IPython will raise a `KillEmbeded` Exception on exit. | |
56 |
|
56 | This is useful to permanently exit a loop that create IPython embed | ||
57 | This function (after asking for confirmation) sets an internal flag so |
|
57 | instance. | |
58 | that an embedded IPython will raise a `KillEmbeded` Exception on exit. This is useful to |
|
58 | """ | |
59 | permanently exit a loop that create IPython embed instance. |
|
59 | ||
60 |
|
60 | self.shell.should_raise = True | ||
61 | Available only for Python 3. |
|
61 | self.shell.ask_exit() | |
62 | """ |
|
|||
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 |
|
||||
78 | if should_raise: |
|
|||
79 | 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.") |
|
|||
84 |
|
62 | |||
85 |
|
63 | |||
86 |
|
64 |
General Comments 0
You need to be logged in to leave comments.
Login now