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