Show More
@@ -1,8 +1,8 b'' | |||||
1 | """Utilities for connecting to kernels |
|
1 | """Utilities for connecting to kernels | |
2 |
|
2 | |||
3 | There is a ConnectionFileMixin class which encapsulates the logic related to |
|
3 | Notable contents: | |
4 | writing and reading connections files |
|
4 | - ConnectionFileMixin class | |
5 |
|
5 | encapsulates the logic related to writing and reading connections files. | ||
6 | """ |
|
6 | """ | |
7 | # Copyright (c) IPython Development Team. |
|
7 | # Copyright (c) IPython Development Team. | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
@@ -488,8 +488,8 b' class ConnectionFileMixin(Configurable):' | |||||
488 | self.log.debug(u"Loading connection file %s", self.connection_file) |
|
488 | self.log.debug(u"Loading connection file %s", self.connection_file) | |
489 | with open(self.connection_file) as f: |
|
489 | with open(self.connection_file) as f: | |
490 | cfg = json.load(f) |
|
490 | cfg = json.load(f) | |
491 |
self.transport = cfg.get('transport', |
|
491 | self.transport = cfg.get('transport', self.transport) | |
492 |
self.ip = cfg.get('ip', |
|
492 | self.ip = cfg.get('ip', self._ip_default()) | |
493 |
|
493 | |||
494 | for name in port_names: |
|
494 | for name in port_names: | |
495 | if getattr(self, name) == 0 and name in cfg: |
|
495 | if getattr(self, name) == 0 and name in cfg: |
@@ -1,15 +1,7 b'' | |||||
1 | """An Application for launching a kernel |
|
1 | """An Application for launching a kernel | |
2 |
|
||||
3 | Authors |
|
|||
4 | ------- |
|
|||
5 | * MinRK |
|
|||
6 | """ |
|
2 | """ | |
7 | #----------------------------------------------------------------------------- |
|
3 | # Copyright (c) IPython Development Team. | |
8 | # Copyright (C) 2011 The IPython Development Team |
|
4 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
|||
10 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
11 | # the file COPYING.txt, distributed as part of this software. |
|
|||
12 | #----------------------------------------------------------------------------- |
|
|||
13 |
|
5 | |||
14 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
15 | # Imports |
|
7 | # Imports | |
@@ -19,7 +11,6 b' from __future__ import print_function' | |||||
19 |
|
11 | |||
20 | # Standard library imports |
|
12 | # Standard library imports | |
21 | import atexit |
|
13 | import atexit | |
22 | import json |
|
|||
23 | import os |
|
14 | import os | |
24 | import sys |
|
15 | import sys | |
25 | import signal |
|
16 | import signal | |
@@ -41,13 +32,13 b' from IPython.core.shellapp import (' | |||||
41 | from IPython.utils import io |
|
32 | from IPython.utils import io | |
42 | from IPython.utils.localinterfaces import localhost |
|
33 | from IPython.utils.localinterfaces import localhost | |
43 | from IPython.utils.path import filefind |
|
34 | from IPython.utils.path import filefind | |
44 | from IPython.utils.py3compat import str_to_bytes |
|
|||
45 | from IPython.utils.traitlets import ( |
|
35 | from IPython.utils.traitlets import ( | |
46 | Any, Instance, Dict, Unicode, Integer, Bool, CaselessStrEnum, |
|
36 | Any, Instance, Dict, Unicode, Integer, Bool, CaselessStrEnum, | |
47 | DottedObjectName, |
|
37 | DottedObjectName, | |
48 | ) |
|
38 | ) | |
49 | from IPython.utils.importstring import import_item |
|
39 | from IPython.utils.importstring import import_item | |
50 | from IPython.kernel import write_connection_file |
|
40 | from IPython.kernel import write_connection_file | |
|
41 | from IPython.kernel.connect import ConnectionFileMixin | |||
51 |
|
42 | |||
52 | # local imports |
|
43 | # local imports | |
53 | from .heartbeat import Heartbeat |
|
44 | from .heartbeat import Heartbeat | |
@@ -113,7 +104,8 b' To read more about this, see https://github.com/ipython/ipython/issues/2049' | |||||
113 | # Application class for starting an IPython Kernel |
|
104 | # Application class for starting an IPython Kernel | |
114 | #----------------------------------------------------------------------------- |
|
105 | #----------------------------------------------------------------------------- | |
115 |
|
106 | |||
116 |
class IPKernelApp(BaseIPythonApplication, InteractiveShellApp |
|
107 | class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, | |
|
108 | ConnectionFileMixin): | |||
117 | name='ipkernel' |
|
109 | name='ipkernel' | |
118 | aliases = Dict(kernel_aliases) |
|
110 | aliases = Dict(kernel_aliases) | |
119 | flags = Dict(kernel_flags) |
|
111 | flags = Dict(kernel_flags) | |
@@ -227,31 +219,6 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
227 | s.bind("ipc://%s" % path) |
|
219 | s.bind("ipc://%s" % path) | |
228 | return port |
|
220 | return port | |
229 |
|
221 | |||
230 | def load_connection_file(self): |
|
|||
231 | """load ip/port/hmac config from JSON connection file""" |
|
|||
232 | try: |
|
|||
233 | fname = filefind(self.connection_file, ['.', self.profile_dir.security_dir]) |
|
|||
234 | except IOError: |
|
|||
235 | self.log.debug("Connection file not found: %s", self.connection_file) |
|
|||
236 | # This means I own it, so I will clean it up: |
|
|||
237 | atexit.register(self.cleanup_connection_file) |
|
|||
238 | return |
|
|||
239 | self.log.debug(u"Loading connection file %s", fname) |
|
|||
240 | with open(fname) as f: |
|
|||
241 | s = f.read() |
|
|||
242 | cfg = json.loads(s) |
|
|||
243 | self.transport = cfg.get('transport', self.transport) |
|
|||
244 | if self.ip == self._ip_default() and 'ip' in cfg: |
|
|||
245 | # not overridden by config or cl_args |
|
|||
246 | self.ip = cfg['ip'] |
|
|||
247 | for channel in ('hb', 'shell', 'iopub', 'stdin', 'control'): |
|
|||
248 | name = channel + '_port' |
|
|||
249 | if getattr(self, name) == 0 and name in cfg: |
|
|||
250 | # not overridden by config or cl_args |
|
|||
251 | setattr(self, name, cfg[name]) |
|
|||
252 | if 'key' in cfg: |
|
|||
253 | self.config.Session.key = str_to_bytes(cfg['key']) |
|
|||
254 |
|
||||
255 | def write_connection_file(self): |
|
222 | def write_connection_file(self): | |
256 | """write connection info to JSON file""" |
|
223 | """write connection info to JSON file""" | |
257 | cf = self.abs_connection_file |
|
224 | cf = self.abs_connection_file | |
@@ -285,6 +252,13 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
285 | if not self.connection_file: |
|
252 | if not self.connection_file: | |
286 | self.connection_file = "kernel-%s.json"%os.getpid() |
|
253 | self.connection_file = "kernel-%s.json"%os.getpid() | |
287 | try: |
|
254 | try: | |
|
255 | self.connection_file = filefind(self.connection_file, ['.', self.profile_dir.security_dir]) | |||
|
256 | except IOError: | |||
|
257 | self.log.debug("Connection file not found: %s", self.connection_file) | |||
|
258 | # This means I own it, so I will clean it up: | |||
|
259 | atexit.register(self.cleanup_connection_file) | |||
|
260 | return | |||
|
261 | try: | |||
288 | self.load_connection_file() |
|
262 | self.load_connection_file() | |
289 | except Exception: |
|
263 | except Exception: | |
290 | self.log.error("Failed to load connection file: %r", self.connection_file, exc_info=True) |
|
264 | self.log.error("Failed to load connection file: %r", self.connection_file, exc_info=True) |
General Comments 0
You need to be logged in to leave comments.
Login now