Show More
@@ -56,3 +56,16 b' class ExitAutocall(IPyAutocall):' | |||||
56 |
|
56 | |||
57 | def __call__(self): |
|
57 | def __call__(self): | |
58 | self._ip.ask_exit() |
|
58 | self._ip.ask_exit() | |
|
59 | ||||
|
60 | class ZMQExitAutocall(ExitAutocall): | |||
|
61 | """Exit IPython. Autocallable, so it needn't be explicitly called. | |||
|
62 | ||||
|
63 | Parameters | |||
|
64 | ---------- | |||
|
65 | keep_kernel : bool | |||
|
66 | If True, leave the kernel alive. Otherwise, tell the kernel to exit too | |||
|
67 | (default). | |||
|
68 | """ | |||
|
69 | def __call__(self, keep_kernel=False): | |||
|
70 | self._ip.keepkernel_on_exit = keep_kernel | |||
|
71 | self._ip.ask_exit() |
@@ -199,6 +199,9 b' class InteractiveShell(Configurable, Magic):' | |||||
199 | display_pub_class = Type(DisplayPublisher) |
|
199 | display_pub_class = Type(DisplayPublisher) | |
200 |
|
200 | |||
201 | exit_now = CBool(False) |
|
201 | exit_now = CBool(False) | |
|
202 | exiter = Instance(ExitAutocall) | |||
|
203 | def _exiter_default(self): | |||
|
204 | return ExitAutocall(self) | |||
202 | # Monotonically increasing execution counter |
|
205 | # Monotonically increasing execution counter | |
203 | execution_count = Int(1) |
|
206 | execution_count = Int(1) | |
204 | filename = Unicode("<ipython console>") |
|
207 | filename = Unicode("<ipython console>") | |
@@ -1025,9 +1028,8 b' class InteractiveShell(Configurable, Magic):' | |||||
1025 | # Store myself as the public api!!! |
|
1028 | # Store myself as the public api!!! | |
1026 | ns['get_ipython'] = self.get_ipython |
|
1029 | ns['get_ipython'] = self.get_ipython | |
1027 |
|
1030 | |||
1028 | exiter = ExitAutocall(self) |
|
|||
1029 | for n in ['exit', 'Exit', 'quit', 'Quit']: |
|
1031 | for n in ['exit', 'Exit', 'quit', 'Quit']: | |
1030 | ns[n] = exiter |
|
1032 | ns[n] = self.exiter | |
1031 |
|
1033 | |||
1032 | # Sync what we've added so far to user_ns_hidden so these aren't seen |
|
1034 | # Sync what we've added so far to user_ns_hidden so these aren't seen | |
1033 | # by %who |
|
1035 | # by %who |
@@ -24,6 +24,7 b' from IPython.core.interactiveshell import (' | |||||
24 | InteractiveShell, InteractiveShellABC |
|
24 | InteractiveShell, InteractiveShellABC | |
25 | ) |
|
25 | ) | |
26 | from IPython.core import page |
|
26 | from IPython.core import page | |
|
27 | from IPython.core.autocall import ZMQExitAutocall | |||
27 | from IPython.core.displayhook import DisplayHook |
|
28 | from IPython.core.displayhook import DisplayHook | |
28 | from IPython.core.displaypub import DisplayPublisher |
|
29 | from IPython.core.displaypub import DisplayPublisher | |
29 | from IPython.core.macro import Macro |
|
30 | from IPython.core.macro import Macro | |
@@ -105,6 +106,10 b' class ZMQInteractiveShell(InteractiveShell):' | |||||
105 | displayhook_class = Type(ZMQDisplayHook) |
|
106 | displayhook_class = Type(ZMQDisplayHook) | |
106 | display_pub_class = Type(ZMQDisplayPublisher) |
|
107 | display_pub_class = Type(ZMQDisplayPublisher) | |
107 |
|
108 | |||
|
109 | exiter = Instance(ZMQExitAutocall) | |||
|
110 | def _exiter_default(self): | |||
|
111 | return ZMQExitAutocall(self) | |||
|
112 | ||||
108 | keepkernel_on_exit = None |
|
113 | keepkernel_on_exit = None | |
109 |
|
114 | |||
110 | def init_environment(self): |
|
115 | def init_environment(self): | |
@@ -593,15 +598,4 b' class ZMQInteractiveShell(InteractiveShell):' | |||||
593 | ) |
|
598 | ) | |
594 | self.payload_manager.write_payload(payload) |
|
599 | self.payload_manager.write_payload(payload) | |
595 |
|
600 | |||
596 | def magic_Exit(self, parameter_s=''): |
|
|||
597 | """Exit IPython. If the -k option is provided, the kernel will be left |
|
|||
598 | running. Otherwise, it will shutdown without prompting. |
|
|||
599 | """ |
|
|||
600 | opts,args = self.parse_options(parameter_s,'k') |
|
|||
601 | self.shell.keepkernel_on_exit = opts.has_key('k') |
|
|||
602 | self.shell.ask_exit() |
|
|||
603 |
|
||||
604 | # Add aliases as magics so all common forms work: exit, quit, Exit, Quit. |
|
|||
605 | magic_exit = magic_quit = magic_Quit = magic_Exit |
|
|||
606 |
|
||||
607 | InteractiveShellABC.register(ZMQInteractiveShell) |
|
601 | InteractiveShellABC.register(ZMQInteractiveShell) |
General Comments 0
You need to be logged in to leave comments.
Login now