Show More
@@ -62,6 +62,7 b' kernel_aliases.update({' | |||
|
62 | 62 | 'stdin' : 'KernelApp.stdin_port', |
|
63 | 63 | 'f' : 'KernelApp.connection_file', |
|
64 | 64 | 'parent': 'KernelApp.parent', |
|
65 | 'transport': 'KernelApp.transport', | |
|
65 | 66 | }) |
|
66 | 67 | if sys.platform.startswith('win'): |
|
67 | 68 | kernel_aliases['interrupt'] = 'KernelApp.interrupt' |
@@ -98,7 +99,6 b' class KernelApp(BaseIPythonApplication):' | |||
|
98 | 99 | heartbeat = Instance(Heartbeat) |
|
99 | 100 | session = Instance('IPython.zmq.session.Session') |
|
100 | 101 | ports = Dict() |
|
101 | _full_connection_file = Unicode() | |
|
102 | 102 | |
|
103 | 103 | # inherit config file name from parent: |
|
104 | 104 | parent_appname = Unicode(config=True) |
@@ -112,8 +112,16 b' class KernelApp(BaseIPythonApplication):' | |||
|
112 | 112 | |
|
113 | 113 | # connection info: |
|
114 | 114 | transport = CaselessStrEnum(['tcp', 'ipc'], default_value='tcp', config=True) |
|
115 |
ip = Unicode( |
|
|
115 | ip = Unicode(config=True, | |
|
116 | 116 | help="Set the IP or interface on which the kernel will listen.") |
|
117 | def _ip_default(self): | |
|
118 | if self.transport == 'ipc': | |
|
119 | if self.connection_file: | |
|
120 | return os.path.splitext(self.abs_connection_file)[0] + '-ipc' | |
|
121 | else: | |
|
122 | return 'kernel-ipc' | |
|
123 | else: | |
|
124 | return LOCALHOST | |
|
117 | 125 | hb_port = Integer(0, config=True, help="set the heartbeat port [default: random]") |
|
118 | 126 | shell_port = Integer(0, config=True, help="set the shell (ROUTER) port [default: random]") |
|
119 | 127 | iopub_port = Integer(0, config=True, help="set the iopub (PUB) port [default: random]") |
@@ -122,9 +130,16 b' class KernelApp(BaseIPythonApplication):' | |||
|
122 | 130 | help="""JSON file in which to store connection info [default: kernel-<pid>.json] |
|
123 | 131 | |
|
124 | 132 | This file will contain the IP, ports, and authentication key needed to connect |
|
125 |
clients to this kernel. By default, this file will be created in the security |
|
|
133 | clients to this kernel. By default, this file will be created in the security dir | |
|
126 | 134 | of the current profile, but can be specified by absolute path. |
|
127 | 135 | """) |
|
136 | @property | |
|
137 | def abs_connection_file(self): | |
|
138 | if os.path.basename(self.connection_file) == self.connection_file: | |
|
139 | return os.path.join(self.profile_dir.security_dir, self.connection_file) | |
|
140 | else: | |
|
141 | return self.connection_file | |
|
142 | ||
|
128 | 143 | |
|
129 | 144 | # streams, etc. |
|
130 | 145 | no_stdout = Bool(False, config=True, help="redirect stdout to the null device") |
@@ -141,7 +156,7 b' class KernelApp(BaseIPythonApplication):' | |||
|
141 | 156 | """) |
|
142 | 157 | interrupt = Integer(0, config=True, |
|
143 | 158 | help="""ONLY USED ON WINDOWS |
|
144 |
Interrupt this process when the parent is signal |
|
|
159 | Interrupt this process when the parent is signaled. | |
|
145 | 160 | """) |
|
146 | 161 | |
|
147 | 162 | def init_crash_handler(self): |
@@ -158,11 +173,20 b' class KernelApp(BaseIPythonApplication):' | |||
|
158 | 173 | |
|
159 | 174 | def _bind_socket(self, s, port): |
|
160 | 175 | iface = '%s://%s' % (self.transport, self.ip) |
|
161 |
if |
|
|
176 | if self.transport == 'tcp': | |
|
177 | if port <= 0: | |
|
162 | 178 | port = s.bind_to_random_port(iface) |
|
163 | 179 | else: |
|
164 | c = ':' if self.transport == 'tcp' else '-' | |
|
165 | s.bind(iface + c + str(port)) | |
|
180 | s.bind("tcp://%s:%i" % (self.ip, port)) | |
|
181 | elif self.transport == 'ipc': | |
|
182 | if port <= 0: | |
|
183 | for port in range(1,1024): | |
|
184 | path = "%s-%i" % (self.ip, port) | |
|
185 | if not os.path.exists(path): | |
|
186 | break | |
|
187 | else: | |
|
188 | path = "%s-%i" % (self.ip, port) | |
|
189 | s.bind("ipc://%s" % path) | |
|
166 | 190 | return port |
|
167 | 191 | |
|
168 | 192 | def load_connection_file(self): |
@@ -179,7 +203,7 b' class KernelApp(BaseIPythonApplication):' | |||
|
179 | 203 | s = f.read() |
|
180 | 204 | cfg = json.loads(s) |
|
181 | 205 | self.transport = cfg.get('transport', self.transport) |
|
182 |
if self.ip == |
|
|
206 | if self.ip == self._ip_default() and 'ip' in cfg: | |
|
183 | 207 | # not overridden by config or cl_args |
|
184 | 208 | self.ip = cfg['ip'] |
|
185 | 209 | for channel in ('hb', 'shell', 'iopub', 'stdin'): |
@@ -192,19 +216,15 b' class KernelApp(BaseIPythonApplication):' | |||
|
192 | 216 | |
|
193 | 217 | def write_connection_file(self): |
|
194 | 218 | """write connection info to JSON file""" |
|
195 | if os.path.basename(self.connection_file) == self.connection_file: | |
|
196 | cf = os.path.join(self.profile_dir.security_dir, self.connection_file) | |
|
197 | else: | |
|
198 | cf = self.connection_file | |
|
219 | cf = self.abs_connection_file | |
|
220 | self.log.debug("Writing connection file: %s", cf) | |
|
199 | 221 | write_connection_file(cf, ip=self.ip, key=self.session.key, transport=self.transport, |
|
200 | 222 | shell_port=self.shell_port, stdin_port=self.stdin_port, hb_port=self.hb_port, |
|
201 | 223 | iopub_port=self.iopub_port) |
|
202 | 224 |
|
|
203 | self._full_connection_file = cf | |
|
204 | ||
|
205 | 225 | def cleanup_connection_file(self): |
|
206 |
cf = self. |
|
|
207 |
self.log.debug(" |
|
|
226 | cf = self.abs_connection_file | |
|
227 | self.log.debug("Cleaning up connection file: %s", cf) | |
|
208 | 228 | try: |
|
209 | 229 | os.remove(cf) |
|
210 | 230 | except (IOError, OSError): |
@@ -684,7 +684,20 b' class KernelManager(Configurable):' | |||
|
684 | 684 | |
|
685 | 685 | transport = CaselessStrEnum(['tcp', 'ipc'], default_value='tcp', config=True) |
|
686 | 686 | |
|
687 |
ip = Unicode(LOCALHOST, config=True |
|
|
687 | ip = Unicode(LOCALHOST, config=True, | |
|
688 | help="""Set the kernel\'s IP address [default localhost]. | |
|
689 | If the IP address is something other than localhost, then | |
|
690 | Consoles on other machines will be able to connect | |
|
691 | to the Kernel, so be careful!""" | |
|
692 | ) | |
|
693 | def _ip_default(self): | |
|
694 | if self.transport == 'ipc': | |
|
695 | if self.connection_file: | |
|
696 | return os.path.splitext(self.connection_file)[0] + '-ipc' | |
|
697 | else: | |
|
698 | return 'kernel-ipc' | |
|
699 | else: | |
|
700 | return LOCALHOST | |
|
688 | 701 | def _ip_changed(self, name, old, new): |
|
689 | 702 | if new == '*': |
|
690 | 703 | self.ip = '0.0.0.0' |
General Comments 0
You need to be logged in to leave comments.
Login now